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' unexpectedwhere 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)