Register now and start sharing your code snippets.
-->
Scheduling jobs to run daily, weekly or monthly with Cron
Shell Script (Bash) posted 9 months ago by christian
Cron syntax and valid values:
1 # +---------------- minute (0 - 59) 2 # | +------------- hour (0 - 23) 3 # | | +---------- day of month (1 - 31) 4 # | | | +------- month (1 - 12) 5 # | | | | +---- day of week (0 - 6) (Sunday=0 or 7) 6 # | | | | | 7 * * * * * command to be executed
Below are a few examples on how to run a script every 10 minutes, every 30 minutes, every hour, daily, weekly, monthly.
Execute crontab -e and add the following (see man crontab):
1 # Every 10 minutes 2 */10 * * * * /home/belsebub/delete_old_stuff.sh 3 4 # Every 30 minutes 5 */30 * * * * /home/belsebub/delete_old_stuff.sh 6 7 # Every 60 minutes 8 */60 * * * * /home/belsebub/delete_old_stuff.sh 9 10 # Every day at 00:00 11 00 00 * * * /home/belsebub/delete_old_stuff.sh 12 13 # Every saturday at 00:00 14 00 00 * * 6 /home/belsebub/delete_old_stuff.sh 15 16 # First day of every month at 00:00 17 00 00 1 * * /home/belsebub/delete_old_stuff.sh
On Debian the configuration goes to /var/spool/cron/crontabs/username.