9:07 PMcrontab: A command in linux to automatically start/repeat a process at certian time and interval
crontab - A command to manage crontab files for each users and schedule commands ans other scripts.
It is meant to be used for scheduling re-occurring jobs. If you want to schedule a job for one time exection, you should use at command in Linux.
Each user can have their own crontab, and though these are files in /var, they are not intended to be edited directly.
Related files: /etc/cron.allow, /etc/cron.deny
To List the cronjobs for a user
The -l option causes the current crontab to be displayed on standard output.
To see cronjobs og other user you can use -u option but you must be superuser to do so.
Delete the cronjobs for a user
The -r option causes the current crontab (cronjobs of current user)to be removed.
The format to create a new cron:
To edit the crontab of a user:
To check if the cronjobs executed or are running
If you are a root user, you can see and edit the cron job of other users.
crontab -u someUser -e
The above command will view/edit the corn jobs of someUser.
Suppose you want to delete some log files from your home directory at every friday of the month at 23:59. How will you do this? Simply type below line in your crontab:
59 23 * * 5 rm *.log
Suppose you want to start a script at 06:10 pm at the end of each month, you can use below cron:
10 18 * * * /path-of-script/script.sh
To run a command every one minute
Though this could not be the requirement, but just for understanding, below line in crontab will cause the CMD to run every minute.
* * * * * CMD
To run a command or script every 5 minute continuously
*/n in the first field (Minute field) means that the command will be execcuted every n minutes. For eg.
*/5 * * * * CMD
So, the above cron will run the CMD every 5 minutes.
To schedule a script/command to execute twice or thrice a day.
0 8,10 * * * CMD
The above cron means the CMD will execute at 8:00 AM as well as 10:00 AM everyday(on weekend also)
To schedule a script/command to execute in period ranging from one to another.
Lets say we want to execute a command starting at 8: 00 AM till 11:00 AM. So, the value '8-11' in the hour field means the command will be executed at 8 AM, 9 AM, 10 AM and at 11 AM.
0 8-11 * * * CMD
Now lets see some special cronjobs:
These special time specification "nicknames" are supported, which replace the 5 initial time and date fields, and are prefixed by the '@' character:
You may also like to see:
|Perl trick to remove Ctrl - M charater from a file|
|XMLLINT command in linux : a validating XML parser|
|Traceroute command in Linux|
|Shift command with examples|
|Some unique and special commands in Linux|
|Total comments: 0|