Menu

Sunday, July 10, 2011

Crontab


  • 1. What is cron?
    • Cron is utility software in Linux/Unix system used to run a set of tasks automatically in the background without any user interference. This is mainly used to automate the process similar to batch file in windows.
    • The tasks i.e. commands should be specified in the crontab file. By default the crontab file will be in /var/spool/cron and the log file of the crontab in /var/log/cron
  • 2. Crontab commands
    • Syntax
    • # crontab -l        - List all the tasks entered in the crontab file.
    • # crontab -e       - Edit the crontab file.
    • # crontab -r        - Remove the crontab file.
  • 3. Crontab syntax 
    • *    *   *   *   * (command to execute/sh file to execute list of commands) 
  • 4. Examples
    • */2 * * * * backup.sh        - Run the backup.sh file for every two minutes.
    • * */12 * * * bakcup.sh      - Run the backup.sh file for every 12 hours.
    • * * 1,15 * * backup.sh      - Run backup.sh file 1st and 15th of every month.
    • * * * 1,6 * backup.sh        - Run backup.sh file on January and June.
    • * * * * 0 backup.sh           - Run backup.sh file every Sunday.