Crontab
Cron is utility to schedule commands at specific time.Cron is generally used for running scheduled backups, monitoring disk space, deleting files (for example log files) periodically which are no longer required, running system maintenance tasks and a lot more.
Format of Crontab:
Minute(0-59) Hour(0-24) Day_of_month(1-31) Month(1-12) Day_of_week(0-6) Command_to_execute
Commands to remember for Cron
#Display contents of crontab
$ crontab -l
#edit cron jobs
$ crontab -e
#edit the crontab of a different user
$ crontab -u <User> -e
#To remove all cron jobs for the current user
$ crontab -r
Example:
To run a cron job at every minute
* * * * * <command-to-execute>
To run cron job at every 5th minute
*/5 * * * * <command-to-execute>
To run a cron job every hour at minute 30
30 * * * * <command-to-execute>
To run a cron job every 2 hours
0 */2 * * * <command-to-execute>
To run a cron job every day at 2 PM
0 14 * * * <command-to-execute>
Cron is utility to schedule commands at specific time.Cron is generally used for running scheduled backups, monitoring disk space, deleting files (for example log files) periodically which are no longer required, running system maintenance tasks and a lot more.
Format of Crontab:
Minute(0-59) Hour(0-24) Day_of_month(1-31) Month(1-12) Day_of_week(0-6) Command_to_execute
Commands to remember for Cron
#Display contents of crontab
$ crontab -l
#edit cron jobs
$ crontab -e
#edit the crontab of a different user
$ crontab -u <User> -e
#To remove all cron jobs for the current user
$ crontab -r
Example:
To run a cron job at every minute
* * * * * <command-to-execute>
To run cron job at every 5th minute
*/5 * * * * <command-to-execute>
To run a cron job every hour at minute 30
30 * * * * <command-to-execute>
To run a cron job every 2 hours
0 */2 * * * <command-to-execute>
To run a cron job every day at 2 PM
0 14 * * * <command-to-execute>
Comments
Post a Comment