A Cron Job is a Linux command for scheduling a task (command). Cron Jobs allow you to automate certain commands or scripts on your server to complete repetitive tasks automatically.
Enter root mode
ubuntu@ubuntu-14:~$ sudo -i
Install cron server
root@ubuntu-14:~# apt-get install cron
Start cron server.
root@ubuntu-14:~# service cron start
Restart cron server.
root@ubuntu-14:~# service cron restart
Is crond (cron server) running?
root@ubuntu-14:~# ps aux | grep cron
root@ubuntu-14:~# ps -ef | grep cron
root@ubuntu-14:~# service cron status
cron start/running, process 1027
You can check /var/log/syslog file to find out if cron service running or not using the grep command as follows:
root@ubuntu-14:~# grep --color -i cron /var/log/syslog
Where are cron logs stored on Ubuntu and how to enable logging.
root@ubuntu-14:~# nano /etc/rsyslog.d/50-default.conf
Find the line:
#cron.* /var/log/cron.log
Uncoment the line (i.e. remove #):
cron.* /var/log/cron.log
Restart the following two services:
root@ubuntu-14:~# service rsyslog restart
root@ubuntu-14:~# service cron restart
Using Cron Help
root@ubuntu-14:~# man crontab
root@ubuntu-14:~# man 5 crontab
List Cron Jobs
root@ubuntu-14:~# crontab -l
In the output command will show you all the list of cron jobs running under this user.
If you want to display the cron jobs of another user then we can check that by using following command.
root@ubuntu-14:~# crontab -l -u username
Edit Cron Jobs
To add the new cron job or editing the existing one we will use the following crontab command.
root@ubuntu-14:~# crontab -e
Remove Cron Jobs
Following command can be used to remove the scheduled cron jobs.
root@ubuntu-14:~# crontab -r
This will remove all the cronjobs without asking for confirmation. Use -ir if you want to remove cronjobs interactively.
root@ubuntu-14:~# crontab -ir
If you want to remove the cron jobs of another user, execute it as:
root@ubuntu-14:~# crontab -ir -u username
Scheduling Jobs with Crontab
We can schedule cron jobs by using its special syntax. There are also different short hand commands that can be used in crontab file to make administering it with ease.
The syntax of crontab entry should be as follow:
* * * * * command to be executed
- - - - -
I I I I I
I I I I I
I I I I +----- day of week (0 - 6) (0 is Sunday, or use names)
I I I +---------- month (1 - 12)
I I +--------------- day of month (1 - 31)
I +-------------------- hour (0 - 23)
+------------------------- min (0 - 59)
Where:
* = every minute
*= every hour
*= every day
*= every day month
* = every day of week
Minute => In which minute the job to be executed.
Hour => In which Hour the job need to be executed.
DOM => The Day Of Month in which the job need to be executed
Month => In which month the job need to be executed
DOW => The Day of Week in which the job need to be executed.
Online Crontab Calculator
https://crontab.guru/
http://crontab-generator.org/
http://www.cronmaker.com/
https://crontranslator.appspot.com/
http://www.generateit.net/cron-job/
http://corntab.com/
0 comments:
Post a Comment