[Techtalk] Cron

Magni Onsoien magnio+lc-techtalk at pvv.ntnu.no
Tue Nov 5 21:09:14 EST 2002

On Tue, Nov 05, 2002 at 06:44:34PM +0100, Dan Richter said:

> >Actually, it is possible to get a permission denied error as root.
> Permissions on the script are okay. I was actually referring to the 
> directory and the log file (which don't belong to root).

And you are sure root can write to it? Not on a readonly disk or mounted
via NFS non-writeable for root?

> >Which distro and version are you running?
> I think it's Red Hat 7.2.

cat /etc/redhat-release should give you a clue. Or 'rpm -q

> The log files are blank. The only way I knew there was an error was by 
> executing the script myself: the error was spewed to stderr. But in the 
> crontab, stderr is piped to a log file (which is blank). The script 
> produces output even if there is no error, so there is no reason for the 
> log file to be blank.

Have you tried to get all output mailed to yourself i stead of written
to a log file? Set MAILTO=your.address at domain.com at the beginning of
the crontab should do it (maybe depending on exactly how you run it
from cron: do you use 'crontab -e' to edit the crontab to add your
script, or do you use some other way?).

> The purpose of the script is to check to make sure a program is executing 
> and, if it is not, run it. This works fine when I execute the script 
> myself, but it doesn't work from cron. I've even told the script to mail me 
> (first command in the script), but it doesn't.

Do you use full path to ALL external programs in your script? Remember
that PATH is different in a non-interactive shell and a login shell.

Use /bin/sh -x (or /bin/bash -x) instead of just /bin/sh at the
beginning of the script, this will show the commands executed by the

Magni :)
sash is very good for you.

More information about the Techtalk mailing list