LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Script not being run in cron.daily (https://www.linuxquestions.org/questions/linux-general-1/script-not-being-run-in-cron-daily-673564/)

hazmatt20 10-01-2008 11:54 AM

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 12: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-01-2008 11:42 PM

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

jschiwal 10-02-2008 12: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 11:26 AM

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?

jailbait 10-03-2008 12:07 PM

Quote:

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 06:24 PM

I tried:
Code:

#!/bin/bash

/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 12:08 AM

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.

chrism01 10-07-2008 01: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 01:03 AM

I ran
Code:

/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 08:24 PM

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.