Crontab is a scheduling tool for programs/scripts/applications to run at defined intervals without administrator interventions.
So where we require crontab?
Where there is no need for admin intervention such as taking daily backups, sending mails to particular user, monitoring network etc.
Coming to scheduling task, crontab uses clock daemon (/usr/sbin/cron or /usr/sbin/crond) that executes commands at specific times. The corn table for each user is located in /var/spool/cron/ with their names
suppose if you want to see cron table for root then the file you have to look for cron job for root is /var/spool/cron/root.
Crontab file content
The content of the file can be divided in to 6 fields(first 5 for specifying time and last one for executing scripts/app etc)
The first five fields are separated by either a space or a tab and represent the following unit’s, respectively:
* minutes (0-59) * hour (0-23) * day of the month (1-31) * month of the year (1-12) * day of the week (0-6, 0=Sunday)
Configuration of crontab for user
Example 1: Creating crontab for a user
#crontab -e -u username
-e is for specifying editing and -u for specifying user name when you are scheduling crontabs for other users
if users want to schedule their own he can just give (crontab -e)
Example:
I will take one example here to explain crontab,suppose I want to execute one script located in /var/test/script.sh and save the output to /temp/script.out should be executed every 10th of each month at 9:43pm
#crontab -e -u surya
so here it will open a temporary in /tmp folder
43 21 10 * * /var/test/script.sh > /temp/script.out
here * in month field and week field indicates any month and any week execute this script
after entering the values save and exit the file, A file will be created in as /var/spool/cron/surya with the above content
Example2: seeing crontab for a particular user
#crontab -l -u username
Example
#crontab -l -u surya
If you are a user and want to see your crontab you can just give (crontab -l)
Example3: Removing crontab for particular user
This can be achieved in two ways
1)removing all the crontab entries for a particular user
#crontab -r -l username
Example
#crontab -r -l surya
2)removing one task for particular user,for doing this we have to edit the crontab
#crontab -e -l username
Please see here some of the crontab issues
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018