How to check if my cron jobs are executed?
Solution 1:
If you want to check if they are executed, use:
grep -i cron /var/log/syslog
Solution 2:
Just do what cron does.
run-parts -v /etc/cron.daily
run-parts -v /etc/cron.weekly
- etc
-v
prints the script names before they are run.
Solution 3:
If you would like to just check that cron
is running, you can do the following:
service cron status
Solution 4:
This question is really about anacron
, which runs these cycled cron jobs.
First, make sure that your anacrontab
file has valid syntax. If you see nothing, then it's fine:
/usr/sbin/anacron -T
Next, you can run all of the scripts that will run hourly, daily, weekly and monthly. This could be a lot, so have a look in /etc/cron.{hourly|daily|weekly|monthly}
to see what's going to happen. To run them all:
sudo su -
cd / && run-parts --report /etc/cron.hourly
cd / && run-parts --report /etc/cron.daily
cd / && run-parts --report /etc/cron.weekly
cd / && run-parts --report /etc/cron.monthly
Finally see if anacron's scheduling system is working correctly. You can do this with:
/usr/sbin/anacron -n -f cron.monthly
(-n
means Run jobs now, -f
means force, ignoring timestamps). That will run the monthly jobs. It will run silently in the background, and you will receive an email when the job is done. There will be a random delay before the job starts, which is specified in the delay column in anacrontab
.
You can see what's happening using:
grep monthly /var/log/syslog
You should also be able to cause anacron to run any of the cycles by doing something like this:
echo "20160101" | cat > /var/spool/anacron/cron.monthly
/usr/sbin/anacron cron.monthly
This enters a very old date into the spool file. That tells anacron that the monthly job was last run more than a month ago, and it will schedule it to run now or shortly.