Technical article 110004

Shell scripts with rcmd fail when run as "at" or "batch" jobs.

OpenServer 5.0.0OpenServer 5.0.2OpenServer 5.0.4OpenServer 5.0.5UnixWare 7.0.0UnixWare 7.0.1

Written · Last revised

Problem

When I run a script containing an rcmd command as an "at" or "batch" job, the commands after the rcmd command do not get executed, and I get an error similar to:

sh: syntax error at line 72: `end of file' unexpected

where the line number is much greater than the number of lines in my script.

Cause

When a script is run as an "at" or "batch" job, it is passed as
standard input to the shell.  The rcmd command also reads from
standard input so when it executes, it 'consumes' the remainder of
the script.  This is why the "end of file" unexpected message is
seen, and explains why, when control returns to the script, the
statements after the rcmd don't get executed.
The line number refers to the line in the stream of commands "at"
is executing.  This includes the environment, followed by
/usr/lib/cron/.proto, followed by the actual script.  This full
stream can be seen by scheduling an "at" job that does not get run
immediately and by looking in the /usr/spool/cron/atjobs directory.

Solution

The problem is fixed by passing the -n option to rcmd which makes it read from /dev/null.

NOTE: This problem is not seen when running ./script from the command line because the standard input is the keyboard, not the shell script. However, it can be reproduced by running sh < script.

See also

man pages for rcmd(TC)

From the Xinuos technical article database, record 110004. Reproduced with permission. The original is at www.sco.com/ta/110004, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.