Scheduled Task Service
One-time Scheduled tasks:
For example: Tonight 11.30 open website service (new website publish)
Long-term planning tasks:
Example: Weekly 1.3.5 pack backup/home/wwwroot to backup.tar.gz
Disposable tasks:
It is implemented by the ATD service/process, and the planned management Operations Command is "at"
Parameters |
Role |
At < Time > |
Schedule a one-time task |
ATQ or At-l |
View the Task List |
at-c Serial Number |
previewing tasks and setting up the environment |
Atrm |
Delete a task |
You typically use the AT command to set up scheduled tasks using either interactive or non-interactive methods.
Ctrl+d Save exit after completion
Interactive:
[[email protected] ~]# at 23:30
at> systemctl start httpd
At> <EOT>
Job 2 at Fri Sep 8 23:30:00 2017
[[email protected] ~]# atq # View Task List
2 Fri Sep 8 23:30:00 a root
[[email protected] ~]# at-c 2 # Preview
#!/bin/sh
# Atrun Uid=0 gid=0
# Mail Root 0
Non-interactive: ( transfer directly to the at command using the echo statement )
[Email protected] ~]# echo "systemctl start httpd" | At 23:30
Job 3 at Fri Sep 8 23:30:00
[Email protected] ~]# ATQ
3 Fri Sep 8 23:30:00 a root
[Email protected] ~]# ATRM 3 #删除序号为3的任务
[[email protected] ~]# atq # View Task List
[Email protected] ~]#
Long-term planning tasks:
Cron Service is required to establish long-term planning tasks
Create and edit a scheduled task:crontab-e [-u user Name]
View Scheduled tasks:crontab-l [-u user Name]
Delete Scheduled task:Crontab-r [-u user Name]
Edit a fixed format:
* * * * * (full path command)
Available cron Service Settings 1.3.5 of the morning 3.25 backup/home/wwwroot directory for backup.tar.gz
But the command in the inside must take the full path (because of the problem of environment variables)
The method for querying the full path of a command is:
[email protected] ~]# which tar
/usr/bin/tar
To start editing a scheduled task:
[Email protected] ~]# CRONTAB-E
no crontab for root-using an empty one
Crontab:installing New Crontab
[Email protected] ~]# crontab-l
* * 1,3,5/USR/BIN/TAR-ZVCF backup.tar.gz/home/wwwroot
[Email protected] ~]#
The cache file in the TMP directory is emptied by setting the 1 o'clock in the morning of the week 1-5:
[Email protected] ~]# CRONTAB-E
crontab:installing New Crontab
[Email protected] ~]# crontab-l
* * 1,3,5/USR/BIN/TAR-ZVCF backup.tar.gz/home/wwwroot
0 * * 1-5/usr/bin/rm-rf/tmp/*
linux[Basic]-19-Scheduled Task service [01]