LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   script not executed by cron.daily (http://www.linuxquestions.org/questions/linux-newbie-8/script-not-executed-by-cron-daily-697606/)

hopefull 01-15-2009 05:05 PM

script not executed by cron.daily
 
I have a strange problem with cron.daily

My script is very simple:
cat my_script

#!/bin/sh

/usr/bin/touch /home/user_test/touch_cron

From shell this script is correctly executed; also
run-parts /etc/cron.daily

executes correctly the script

But if i put it in cron.daily, it is not executed

I have already checked cron is running and permissions on files and directory are ok

I do not understand, can sameone hep me?
Thanks

gaurav.s.agrawal 01-15-2009 05:21 PM

Could you try redirecting both the output and error to a log file. I am not sure it will work, but it will be worth trying.

Hope this helps !!!

hopefull 01-15-2009 05:41 PM

/usr/bin/touch /home/user_test/touch_cron > /home/user_test/error 2>&1

but i have same prblem, script is not executed in cron.daily

yzhong 01-15-2009 05:47 PM

Did you check the error log, like /var/log/cron?

hopefull 01-15-2009 06:12 PM

yes
the only message is as:

Jan 16 01:32:01 localhost /usr/sbin/cron[3755]: (*system*) RELOAD (/etc/crontab)
Jan 16 01:33:01 localhost /USR/SBIN/CRON[8427]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))


I have seen if i pt file i cron.hourly it works well!

my crontab is:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command
07 * * * * root cd / && run-parts --report /etc/cron.hourly
55 1 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

yzhong 01-15-2009 06:55 PM

in bash "something || other" means that if "something" is FALSE then do "other". In crontab "run-parts --report /etc/cron.daily" will only happen when
"test -x /usr/sbin/anacron" is false. /usr/sbin/anacron does exist.
Testing in the terminal
$ test -x /usr/sbin/anacron || echo "xxx"
gave no echo. changing || to && gave the echo.
Meaning that since /usr/sbin/anacron exists the cron.daily will never happen!

So deleted the "test -x /usr/sbin/anacron ||" part in crontab,like
....
55 1 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
to just
55 1 * * * root cd / && run-parts --report /etc/cron.daily
....

Plus the test for /usr/bin/anacron ensures that cron runs the daily, weekly and monthly script only if anacron is not installed. Take a look at the file /etc/anacrontab. It is also configured to run the daily, weekly, and monthly scripts.If your anacron works well, no need to do the above change. Also grep -i 'anacron' /var/log/syslog will show you some useful info.

hopefull 01-17-2009 09:54 AM

Thanks very much
How you see i 'm really a newbie!


All times are GMT -5. The time now is 08:24 AM.