wiki:linux/Scheduler/cron

at, cron


cron manpage
crontab(1) manpage
crontab(5) manpage


Knowings

Note: This can causing a potential security risk! Read more...

When this is done a graphical cronjob must be added like this example in a cron table

* * * * * DISPLAY=:0 command_to_start_any_GUI

Adding the DISPLAY assignment at the beginning of a cron file will also work:

DISPLAY=:0
  • Every command should put with its full path in a crontab cause cron don't check the PATH entries. This applies to every command inner script which will start with cron, too!
    I don't have tested if these enviroment variable entries at the beginning of a cron file are sufficient:
    SHELL=/bin/bash
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    
  • To prevent receiving mails from cron write this as first line in crontab:
    MAILTO=""
    
  • Never forget: Every crontab must end with a blank line!

Timeline

Format

minutehourday of monthmonthday of week
0-59 0-231-31 1-12 0-7 (0 or 7 is Sun)

Examples

# run five minutes after midnight, every day

minutehourday of monthmonthday of week
5 0 * * *

# run at 2:15pm on the first of every month

minutehourday of monthmonthday of week
15 14 1 * *

# run at 10 pm on weekdays

minutehourday of monthmonthday of week
0 22 * * 1-5

# run 23 minutes after midnight, 2am, 4am ..., every day

minutehour day of monthmonthday of week
23 0-23/2* * *

# every 15 minutes

minutehour day of monthmonthday of week
*/15 * * * *

# every full hour

minutehour day of monthmonthday of week
0 * * * *

sync time every 2 hours

0 */2 * * * /usr/sbin/ntpdate ptbtime1.ptb.de

show a zenity message every full hour

0 * * * * DISPLAY=:0 /usr/bin/zenity --info --text='This is your personal full-hour message :-)'

add a cronjob (every weekday, 15 minutes after every 2 hours) to crontab of current user

$ crontab -l > /tmp/dump; echo '15 */2 * * 1-5 new_cronjob' >> /tmp/dump; crontab /tmp/dump
Last modified 4 years ago Last modified on Jun 17, 2015, 3:53:48 PM