Designdesk

How to use cron to automate everything

Cron is a powerful software that is used to run processes automatically. You can program a backup to synchronise your data every night, launch scripts at startup... The possibilities are endless.

Edit crontab

crontab -e

Syntax :

* * * * * command_to_execute

Time syntax :

* * * * * minute0-59 hour0-23 day.of.month1-31 month1-12 day of week0-7

Here are example lines you can shape

Run backup script ~/bkp/vps.sh everyday at 6 hours 0 minutes 0 6 * * * sh ~/bkp/vps.sh

Run script ~/bkp/documents.sh everyday at 1 hour 30 minutes 30 1 * * * sh ~/bkp/documents.sh

Run script ~/bkp/script.sh every sunday at 3 hour 37 minutes 37 3 * * 7 sh ~/bkp/script.sh

Run script ~/bkp/script.sh everyday at 3 hour 37 minutes, 42 minutes and 45 minutes 37,42,45 3 * * * sh ~/bkp/script.sh

Run dynamic dns service ~/.dynamic.dns/duiadns.bin every 10 minutes */10 * * * * ~/.dynamic.dns/duiadns.bin

After reboot wait 40 seconds then run irssi in a screen @reboot sleep 40 && screen -U -dmS irc irssi

string          meaning
------          -------
@reboot         Run once, at startup of cron.
@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 * * * *".
@every_minute   Run once a minute, "*/1 * * * *".
@every_second   Run once a second.

Source : https://www.freebsd.org/cgi/man.cgi?cron(..)