10

I hope I am asking this question correctly. I am trying to run all jobs that are setup on my server, by nano /etc/crontab I see the list of:

# m h dom mon dow user  command
27 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
58 15    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
0 15    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
20 15    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

Is it possible to execute crontab to kick off all these jobs, or force them to run?

I am trying to confirm they are actually running.

kenorb
  • 6,499
  • 2
  • 46
  • 54
Chris Hough
  • 313
  • 2
  • 4
  • 21

4 Answers4

16

If you want to check if they are executed, use:

grep -i cron /var/log/syslog
masegaloeh
  • 18,236
  • 10
  • 57
  • 106
  • 1
    To test anacron jobs, try this: `echo '20141201' > /var/spool/anacron/cron.monthly; anacron -n -f cron.monthly;`. There are naming constraints on the scripts under `/etc/cron.*`. You might also want to check if `run-parts` is finding your script: `run-parts --test /etc/cron.monthly` – TrinitronX Jan 22 '15 at 09:02
6

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.

Danijel
  • 256
  • 6
  • 19
Nate Rooth
  • 61
  • 1
  • 1
3

If you would like to just check that cron is running, you can do the following:

service cron status

Check log messages from cron with journalctl. See here

journalctl -u cron _TRANSPORT=stdout
ryanjdillon
  • 141
  • 4
2

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.

Simon Woodside
  • 466
  • 1
  • 7
  • 15