15 June 2016

Linux Cron

Cron runs jobs on a schedule on Linux systems.

Edit cron configuration

  1. crontab -e
  2. Insert new text when editing: i
  3. Save and Exit crontab: ESC then :wq

Anatomy of a cron job

Jobs are set to a particular regularity using the format:
m: 0-59 minute e.g. 15 for quater past every hour
h: 0-23 hour of the day, in 24 hours e.g. 23 for 11pm
dom: 1-31 day of month e.g. 20
mon: 1-12 month e.g. 3 for March 
dow: 0-6 day of week Sun=0 e.g. 5 for Friday
user: identity to run command as e.g. root 
command: command to run, e.g. an sh script

Stop cron emails for a job

Send the output of STDOUT (1) and STDERR (2) and send them to /dev/null by appending: > /dev/null 2>&1
00 * * * * salt-call state.highstate > /dev/null 2>&1

No comments:

Post a Comment