A crontab entry in Red Hat is a line in a crontab file that specifies a task to be run at a specific time. The crontab file is a text file that is located in the home directory of each user. The format of a crontab entry is as follows:
minute hour day month weekday commandThe fields are separated by spaces. The meanings of the fields are as follows:
- Minute: The minute of the hour when the job should be run. Can be a number from 0 to 59.
- Hour: The hour of the day when the job should be run. Can be a number from 0 to 23.
- Day: The day of the month when the job should be run. Can be a number from 1 to 31.
- Month: The month of the year when the job should be run. Can be a number from 1 to 12.
- Weekday: The weekday when the job should be run. Can be a number from 0 to 7, where 0 is Sunday and 7 is Saturday.
- Command: The command that should be run. This can be any valid Linux command.
For example, the following crontab entry would run the command /home/user/backup.sh at 10:00 AM every day:
0 10 * * * /home/user/backup.shThe * character is a wildcard that can be used to represent any value. So, the * * * * * crontab entry would run the command every minute, regardless of the hour, day, date, or month.
To create or edit a crontab entry, you can use the crontab command. The following command would open the crontab file for the current user in the vi editor:
crontab -eYou can then add or edit the crontab entries as needed. When you are finished, save and exit the editor.
Here are some additional examples of crontab entries:
- Run the command
/home/user/update.shat 12:00 AM every Sunday:
0 0 * * 0 /home/user/update.sh- Run the command
/home/user/backup.shat 10:00 AM every day, but only on weekdays:
0 10 * * 1-5 /home/user/backup.sh- Run the command
/home/user/send_email.shat 9:00 AM every day, but only on the first day of the month:
0 9 1 * * /home/user/send_email.sh