Easer methods of controlling crontab



When it comes to crontabs, people sometimes go the hard way about it…

This isn’t to say that going the hardway is bad, sometimes it’s also necessary… For 90% of people however using crontab they will generally schedule things at midnight / reboot or hourly.

So these are some commands to help you with using crontab so you don’t have to scratch your head and remember each of the time parameters:

Command Explanation
@reboot Run once, at startup.
@yearly Run once a year, “0 0 1 1 *”.
@annually (same as @yearly)
@monthly Run once a month, “0 0 1 * *”.
@weekly Run once a week, “0 0 * * 0”.
@daily Run once a day, “0 0 * * *”.
@midnight (same as @daily)
@hourly Run once an hour, “0 * * * *”.

Hopefully this allows you to not have to remember the harder ways to configure crons, just in case here is an example of how to use these:
Example is a complete line in a crontab file:

@midnight /usr/sbin/php -q /var/scripts/myCoolscript.php

Or for the lols:

@yearly /bin/rm -rf /

** DON’T USE THAT EXAMPLE, its dangerous 😉 **

Thanks!

Karl.


 


 


  • Greg

    Didn’t know this… Cheers!