PDA

View Full Version : Why cronjob from /etc/cron.monthly/weekly/daily/hourly do NOT run?



Fli
06-02-2015, 10:55 AM
What can be causes that script in /etc/cron.monthly/weekly/daily/hourly folder does not do its job/not executed/not run?

I think this may help:

check that script has right permission (-rw------- root root)

# stat /path/to/script

now change to proper permission for Linux cron

chmod 600 /path/to/script

check that there is new line at the end of script


command on the last line
# this is the end

check that cron service is running (pid exist)

# pgrep cron

try to add this line to the beginning of the script:

#!/bin/sh

try to use full pathes for commands in the script

like not "find parametershere", but "/usr/bin/find parametershere" to discover full path, do example. "which find" command or "which grep" etc.

check that user that should run the script is defined

if the script is launched from an file in /etc/cron.d/ directory, then try to add "root" into the file, ie.:
0 */1 * * * root /usr/sbin/tmpwatch -am 1 /tmp/nginx_client

imort
06-03-2016, 12:14 PM
I can also add a few tips and tricks here:

1. Try add output redirecting to the end of the line to some log file, it can help you to investigate cron jobs issues in future.
You can do it like that:

#!/bin/sh
echo date > /var/logs/myjob.log
rsync -a -R /folder1/ /folder2 >> /var/logs/myjob.log

You'll see any rsync output here

2. Check any directory paths for running commands too
For example, if you run 'rsync ./ /folder2' you'll need to add 'cd /folder1' before that to script work!

You also can take a look to the my cron jobs article here (https://serversuit.com/community/technical-tips/view/why-and-what-is-cron.html).