cron job examples

Rotate logs weekly at 12midnight. (just like the example above)

00   0    *   *   0   /usr/bin/newsyslog

Rotate logs weekly at 12midnight. (instead of 0 for the day of the week we can use Sun for Sunday)

00   0    *   *   Sun /usr/bin/newsyslog

Mail a report to root everyday at 11:59pm (23:59).

59   23  *    *   *   /usr/local/bin/pflogsumm -d today /var/log/maillog | mail -s "mail report" root

Run the backup scripts at 5am on the 3rd (Wed) and 5th (Fri) day of the week. Send any errors to /dev/null

00   5   *    *   3,5 /tools/BACKUP_script.sh >> /dev/null 2>&1

Compress backup files at 6am on the 1st and 15th of the month.

00   6   1,15 *   *   /tools/BACKUP_compress.sh

Refresh the Squid ad blocker server list every 3 days at 12:05am.

05   0    *   *   */3 /tools/ad_servers_newlist.sh

Clear the blocked hosts list at 3:23pm (15:23) every Monday only on even numbered months.

23   15   *   */2 1   /tools/clear_blocked_hosts.sh

Run a script at 8:45pm (20:45) on 2nd and the 16th only in the months of January and April.

45   20   2,16 1,4 *   /tools/a_script.sh

Run a script every day at 8:45pm (20:45) and add a random sleep time between 0 and 300 seconds.

45   20   *   *    *   sleep $(($RANDOM \% 300)); /tools/a_script.sh

Run the script at 23:59 (11:59pm) on the last day of the month.

59   23 28-31 *    *   [ $(date -d +1day +%d) -eq 1 ] && /tools/a_script.sh
# 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"