If you create your cron jobs sometimes you would need to test them just to be sure they work properly. So you need to execute them one by one regardless of their schedule.
The magic of command line makes it easy for us to write a command and do it. So here it is:
crontab -l | grep -v '^#' | cut -f 6- -d ' ' | while read CMD; do eval $CMD; done
How does it work…
I’ll explain all parts of this command one by one.
- This part will list all cron jobs we have defined.
- This part will remove comment lines (all lines beginning with ‘#’).
1grep -v '^#'
- This part will remove time/date settings. It will cut every string from start to the fifth position. e.g. for the command bellow it’ll remove “00 09-18 * * *“00 09-18 * * * /home/john/bin/check-db
1cut -f 6- -d ' '
- This part will execute all commands (one by one) we have defined in our cron list.
1while read CMD; do eval $CMD; done
The bigger problem with crontab entries is that they run without many everyday environment variables set, so I recommend launching them using at to really test them
The really usefully i found here was the graphic with the cron explanation.. but as said Jeremy, at its better for tests. Not surprise if that comes from a winbuntu environment.
In any case, usefully the picture explaining the crond parts.. good made.