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.
|
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 |
The script only uses if, ls, rsync, and echo. It also works on two other computers.
|
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. |
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, test.sh, that contains the following:
#!/bin/bash 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? |
Quote:
which echo -------------------------- Steve Stites |
I tried:
Code:
#!/bin/bash |
Try
"/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. |
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.
|
I ran
Code:
/bin/echo "bin/echo" > /tmp/test 2&>1 |
This
2&>1 ios wrong, should be 2>&1 i/o chn 2 (stderr ) out to address of chan 1 (stdout) |
All times are GMT -5. The time now is 02:59 AM. |