With Crontab you can execute a shell script or a series of Linux commands at a specified time. For example, the system administrator schedules a backup task to run every day
Entry
# crontab–e
This allows you to open your personal crontab profile in edit mode and then add this line:
XX * * * */home/linrui/xxxxxxxx.sh
This will run the specified. sh file at 00:00 every day.
For scripts that resemble a few minutes of execution, add ">/dev/null 2>&1" at the end, which indicates that the system log is not written:
XX * * * */home/linrui/xxxxxxxx.sh >/dev/null 2>&1
Cron description of each item
The following is the format of the crontab file:
{minute} {Hour} {Day-of-month} {Month} {Day-of-week} {Full-path-to-shell-script}
O minute: Interval is 0–59
O Hour: Interval is 0–23
O Day-of-month: Interval is 0–31
O Month: The interval is 1–12. 1 was January. 12 was December.
O Day-of-week: Interval is 0–7. Sunday can be 0 or 7.
Crontab Example
1. Run at 00:01
* * * */home/linrui/xxxx.sh
2, the backup job every weekday 23:59.
* * 1,2,3,4,5/home/linrui/xxxx.sh
or the following:
* * 1-5/home/linrui/xxxx.sh
3. Run a command every minute
*/1 * * * */home/linrui/xxxx.sh
4, 1th number 14:10 per month to run
* */home/linrui/xxxx.sh
Crontab Options for Commands
The following are the valid options for crontab:
Crontab–e: Modify the crontab file. If the file does not exist, it is created automatically.
Crontab–l: Displays the crontab file.
Crontab-r: Delete the crontab file.
Crontab-ir: Alerts the user before deleting the crontab file.
Reprinted from: https://my.oschina.net/u/2288038/blog/485972
Crontab let Linux execute shell scripts at timed intervals