Linux User Customize Method of Scheduling Task Execution for at cron

  • 2021-06-28 09:56:55
  • OfStack

There are two scheduled tasks in the Linux system, one is to perform only one at scheduled task, the other is to perform cron scheduled tasks periodically

at One-time Scheduled Task

describe

Executes a specific command at a specified time (once), also known as a delayed action task.

usage


at   time  [ Enter ]

parameter


at -l      # List single scheduled tasks 
at -r  task id  ## Delete this id Tasks 
at -d  task id  ## Delete this id Tasks 
at -m      # Email a command with no output 
at -M      # Make Output Commands Email 
at -c  task id  ## See this id Action of the task 
at -f  file    ## Use commands recorded in the file as execution commands for delayed tasks 

Example

View system time first


[root@test ~]# date
Thu May 17 18:40:11 CST 2018

Specify a single scheduled task (delayed action)


[root@test ~]# at 18:45       ## On the day 18 : 45 Execution plan (18:45 2018-05-17)
at> date              ## Scheduled Task Content 
at> shutdown -h now         ## Scheduled Task Content 
at> <EOT>              ## End command input, press Ctrl+D Sign out 
job 10 at Thu May 17 18:45:00 2018 ## System prompt has number as 10 Scheduled tasks 

cron Periodically Scheduled Tasks

Scheduling tasks using cron requires that the crond service be turned on and on itself.


# systemctl start crond
# systemctl enable crond

describe

Maintain periodic scheduled task files for each user.

usage


crontab  [ -u  user  ]  [ -l|-r|-e ]

option

参数 用法
-u 指定计划任务的用户,不加-u则默认为当前用户
-l 查看计划任务
-r 删除计划任务
-e 编辑计划任务
-i 使用-r删除计划任务时,要求用户确认删除

corn Scheduled Task Format

第1项 第2项 第3项 第4项 第5项 第6项
命令
00~59 00~23 1~31 1~12 1~7 action

If you need to specify a time period, you can use a horizontal bar (-) to represent a continuous period of time, a comma (,), an asterisk (*), an asterisk (*), and a division sign (/) to indicate an interval.

Example


[root@test ~]# crontab -e
00 20 * * *  rm -fr /tmp/*     ## Every day 20:00 delete /tmp All in 
00 20 1,5 * *  rm -fr /tmp/*    ## monthly 1 Number and 5 Numbered 20:00 , Delete /tmp All in 
00 20 1-5 * *  rm -fr /tmp/*    ## monthly 1 No. to 5 Numbered 20:00 , Delete /tmp All in 
00 20 1,5 3 *  rm -fr /tmp/*    ##3 month 1 Number and 5 Numbered 20:00 , Delete /tmp All in 
00 20 1,5 3 3  rm -fr /tmp/*    ##3 month 1 Number and 5 Number and 3 All weeks of the month 3 Of 20:00 , Delete /tmp All in 
58 20-21 * * *  rm -fr /tmp/*    ## Every day 20-21 Point, per hour 58 Minutes, delete /tmp All in 
*/30 20-21 * * 1-5  rm -fr /tmp/*  ## week 1 To Week 5 Of 20 Point to Point 21 Point, every half hour, delete /tmp All in 
00 */3 * * * who          ## each 3 Hours of full-time user logon checks 

cron Scheduled Task Permissions

In order to control the user's freedom to define their own scheduled tasks, administrators can perform ACL access control.The control files for the at scheduled task are/etc/at.allow and/etc/at.deny, respectively. The default at.llow does not exist.The control files for the cron scheduled task are/etc/cron.allow and/etc/cron.deny, respectively. The default cron.allow does not exist.


Related articles: