Category: crontab

Crontabs – Job scheduler explained

Open crontab using below command:

crontab -e

Its syntax is like below 

* * * * * command/script to be executed/

# Example of job definition:

# .—————- minute (0 – 59)
# |  .————- hour (0 – 23)
# |  |  .———- day of month (1 – 31)
# |  |  |  .——- month (1 – 12) OR jan,feb,mar,apr …
# |  |  |  |  .—- day of week (0 – 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

Listing of Cronjobs can be done using below command:

crontab -l

 Examples:

1. Take backup every day midnight.

0 0 * * * /my/path/to/script/backup.sh

2. Start mongo server @reboot

@reboot /usr/bin/mongod

3.  Mysql database backup every sunday

* * * * 0 /usr/bin/mysqldump -u root -p{root123} userdb2 &gt; /home/nagaraju/myfile_$(date +%Y-%m-%d).sql&nbsp;&nbsp; #every week on Sunday<br />