-   Linux - General (
-   -   Script not being run in cron.daily (

hazmatt20 10-01-2008 12:54 PM

Script not being run in cron.daily
I have a backup script that I run on a few machines, but I'm having a problem with one of them. The script is sitting under /etc/cron.daily, but it isn't run when cron.daily is run. When it is run, it should put the date in a log file, but it doesn't, although it did several weeks ago. I've run cron directly, so I know it's not a problem with cron. I can run the script directly.

jailbait 10-01-2008 01:12 PM

cron has a different PATH than running from the command line. It is a common problem for a script to work from the command line and not work in cron. You can fix this problem by using the complete path for every command in your script.

Another solution is to set the PATH in the cron script to be exactly the same as the PATH used at the command line.

Steve Stites

hazmatt20 10-02-2008 12:42 AM

The script only uses if, ls, rsync, and echo. It also works on two other computers.

jschiwal 10-02-2008 01:54 AM

You should do as Jailbait suggests. One difference could be that on that computer, one of the commands is aliased and that is causing a problem. It is standard practice to always include full pathnames in cron scripts. There is also a security consideration as well.

Another thing to check is that you redirect both stdio and stderr.

hazmatt20 10-03-2008 12:26 PM

The only thing I can think of is that whatever user is calling the scripts in cron.daily doesn't have permission to do some things. I made a script,, that contains the following:

echo 'test `date` >> /var/log/test'

the file exists, but nothing gets written to it. Any suggestions?

Also, by full pathnames do you mean using /bin/echo instead of just echo?

jailbait 10-03-2008 01:07 PM


Originally Posted by hazmatt20 (Post 3299122)

by full pathnames do you mean using /bin/echo instead of just echo?

Yes, assuming that echo is in /bin. You can find out where echo is with:

which echo

Steve Stites

hazmatt20 10-04-2008 07:24 PM

I tried:


/bin/echo "bin/echo" > /tmp/test
/usr/bin/id >> /tmp/test

and nothing happened. Syslog shows that cron.daily was run. What is the problem?

jschiwal 10-07-2008 01:08 AM

"/bin/echo "bin/echo" >/tmp/test 2&>1
/usr/bin/id >> /tmp/test 2&>1

Redirect the file first so that you first redirect stdio to the file before attaching stderr.

chrism01 10-07-2008 02:46 AM

Also, if cron does have an issue, it should/usually email the crontab owner (in this case root) with the problem/results. Login as root on the cmd line and use mailx or mail to check.

hazmatt20 10-10-2008 02:03 AM

I ran

/bin/echo "bin/echo" > /tmp/test 2&>1
and it wrote bin/echo 2 into /tmp/1. Also, mail sent to root is sent to my actual email address, and I've never gotten problems with cron.

chrism01 10-12-2008 09:24 PM



ios wrong, should be


i/o chn 2 (stderr ) out to address of chan 1 (stdout)

All times are GMT -5. The time now is 11:28 AM.