Linux Learning Notes - regular tasks set

Scheduled tasks are used for handling systems need to periodically perform maintenance tasks, such as cleaning up the log, the system checks, etc., can be achieved by crontab and at, command.

crontab more commonly used, according to the minutes, hours, date, month, week to set up a schedule tasks, users can set the parameters and commands, the task will be executed automatically. Common parameters are as follows:

 -u user指定运行此任务的用户是谁,如果不设置,默认是当前登录用户,该选项只有root用户才能使用
-l 显示当前用户的任务
-r 删除当前用户的任务
 -e 更改用户的任务

To use crontab, you must first start the service crontab command is as follows:

See has started up, can be used directly

Now set to automatically run tasks, such as shell scripts loop.sh here have used a test :

Run crontab -e add or change a task list, after running the command will automatically enter vi editing interface:

Every night at one o'clock script execution loop.sh

Minute hour date month week command

00 01 * * * /tmp/loop.sh

View the current timing mission plan with the -l option:

If it is run every Saturday 22:00 loop.sh command, write: 00 22 * ​​* 6 /tmp/loop.sh. Cron job script must have executable permissions x, in order to ensure the script to work.

at

It can be set at a specified time to perform the specified command, crontab command with different tasks defined by the at command, run only once

Common usage:

2:03 days after running the command

See all current tasks at the same using the -l option:

Delete the specified task, you need to see the task id, such as task id on the map is 1:

Other common settings

10 am after three weeks to run the task at 10:00 + 3 weeks /tmp/backup.sh

Tomorrow 16:00 run this task at 4pm tomorrow /tmp/test.sh:

No. 1 22:00 next month to perform this task at 22:00 6/1/2018 /tmp/test.sh:

Two hours later perform this task at now + 2 hours /tmp/test.sh:

After 30 minutes, run the task at now + 30mins /tmp/test.sh:

To view a task we have just set:

Guess you like

Origin blog.csdn.net/qq_30242987/article/details/88814650