I have set up a cronjob for root user in ubuntu environment as follows by typing crontab -e
34 11 * * * sh /srv/www/live/CronJobs/daily.sh 0 08 * * 2 sh /srv/www/live/CronJobs/weekly.sh 0 08 1 * * sh /srv/www/live/CronJobs/monthly.sh But the cronjob does not run. I have tried checking if the cronjob is running using pgrep cron and that gives process id 3033. The shell script calls a python file and is used to send an email. Running the python file is ok. There's no error in it but the cron doesn't run. The daily.sh file has the following code in it.
python /srv/www/live/CronJobs/daily.py python /srv/www/live/CronJobs/notification_email.py python /srv/www/live/CronJobs/log_kpi.py
Crontab might fail for a variety of reasons: The first reason is that your cron daemon might not be working for any reason, resulting in your crontab failing. There also exists a possibility that your system's environment variables are not settled correctly.
To check to see if the cron daemon is running, search the running processes with the ps command. The cron daemon's command will show up in the output as crond. The entry in this output for grep crond can be ignored but the other entry for crond can be seen running as root. This shows that the cron daemon is running.
Cron reads the crontab (cron tables) for predefined commands and scripts. By using a specific syntax, you can configure a cron job to schedule scripts or other commands to run automatically.
Here's a checklist guide to debug not running cronjobs:
ps ax | grep cron and look for cron.service cron start or service cron restart * * * * * /bin/echo "cron works" >> /tmp/file/tmp which does not currently exist should always be writable.2>&1 to include standard error as well as standard output, or separately output standard error to another file with 2>>/tmp/errors /var/log/cron.log or /var/log/messages for errors.grep CRON /var/log/syslog /var/log/cron chmod +x /var/www/app/cron/do-stuff.php PATH, as their value will likely not be the same under cron as under an interactive session. See How to get CRON to call in the correct PATHs 30 1 * * * command > /dev/null 2>&1 >/dev/null 2>&1 altogether; or perhaps redirect to a file in a location where you have write access: >>cron.out 2>&1 will append standard output and standard error to cron.out in the invoking user's home directory.cron job, the daemon will try to send you any output or error messages by email. Check your inbox (maybe simply more $MAIL if you don't have a mail client). If mail is not available, maybe check for a file named dead.letter in your home directory, or system log entries saying that the output was discarded. Especially in the latter case, probably edit the job to add redirection to a file, then wait for the job to run, and examine the log file for error messages or other useful feedback./etc/default/cron EXTRA_OPTS="-L 2" service cron restarttail -f /var/log/syslog to see the scripts executed/etc/rsyslog.d/50-default.conf cron.* /var/log/cron.log sudo /etc/init.d/rsyslog restart /var/log/cron.log and look for detailed error output# Minute Hour Day of Month Month Day of Week User Command # (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat) 0 2 * * * root /usr/bin/find This syntax is only correct for the root user. Regular user crontab syntax doesn't have the User field (regular users aren't allowed to run code as any other user);
# Minute Hour Day of Month Month Day of Week Command # (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat) 0 2 * * * /usr/bin/find crontab -l crontab -e, for a specific user: crontab -e -u agentsmith crontab -r If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With