cron is a command provided in Linux to periodically schedule specific tasks.
Set up tasks through contab.
editor settings
When executing crontab -e, the select-editor command is called and the editor is set.
When you want to change the editor, run select-editor or change the value of SELECTED_EDITOR in ~/.selected_editor.
If the desired editor is not found when executing the select-editor command, change the SELECTED_EDITOR value.
When you run the crontab -e command, you can use the value in the following format.
m h dom mon dow command
field allowed values
----- --------------
minute 0–59
hour 0–23
day of month 1–31
month 1–12 (or names, see below)
day of week 0–7 (0 or 7 is Sun, or use names)
(Manual page crontab(5))
Example
The following lists an example of a user crontab file.
# use /bin/bash to run commands, instead of the default /bin/sh
SHELL=/bin/bash
# mail any output to `paul', no matter whose crontab this is
MAILTO=paul
#
# run five minutes after midnight, every day
5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
# run at 2:15pm on the first of every month — output mailed to paul
15 14 1 * * $HOME/bin/monthly
# run at 10 pm on weekdays, annoy Joe
0 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
5 4 * * sun echo "run at 5 after 4 every Sunday"
0 */4 1 * mon echo "run every 4th hour on the 1st and on every Monday"
0 0 */2 * sun echo "run at midn on every Sunday that's an uneven date"
# Run on every second Saturday of the month
0 4 8-14 * * test $(date +\%u) -eq 6 && echo "2nd Saturday"
All the above examples run non-interactive programs. If you wish to run a program that interacts with the
user's desktop you have to make sure the proper environment variable DISPLAY is set.
# Execute a program and run a notification every day at 10:00 am
0 10 * * * $HOME/bin/program | DISPLAY=:0 notify-send "Program run" "$(cat)"
(Manual page crontab(5))
Reserved words can also be used
string meaning
------ -------
@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 * * * *".
(Manual page crontab(5))