1024programmer Linux Scheduled tasks under linux – scheduled tasks that are executed only once – linux operation and maintenance

Scheduled tasks under linux – scheduled tasks that are executed only once – linux operation and maintenance

Scheduled tasks are a very good function provided by the operating system. We often use scheduled tasks to deal with some things, such as regularly backing up website data every day, executing data statistics programs every month, and monitoring the operation of the server (when an error occurs Send a message to the administrator), etc., all of which need to be completed by timing tasks.

The timing tasks under Linux are divided into two categories: timing tasks that are executed only once, and timing tasks that are executed periodically. Today, let’s take a look at the scheduled tasks that are executed only once. The scheduled tasks that are executed periodically will be described in the next article.

atd service

We use the at command to execute the scheduled task only once. If you want to execute the at command, you need to start the atd service first. Check the running status of the atd service and the command to open the atd service is as follows:

# Check the status of the atd service
 # systemctl status atd
 # Enable atd service
 # systemctl start atd

at permission management

When using at to generate When creating a new task, the task will be placed in the /var/spool/at directory in the form of a text file.

# ll /var/spool/at
 total 8
 -rwx------ 1 root root 2890 Nov 7 16:30 a0000201981b23 <===== at generated file
 drwx------ 2 daemon daemon 4096 Nov 7 16:27 spool

For the permission management of at, the system has two special files to specify. These two files are actually the same as the black and white lists we understand. These two files are /etc/at.deny (blacklist), /etc/at.allow (whitelist). The system default at.deny content is empty, and the system default for /etc/at.allow does not exist. If neither of these files exists, only the root user can use the at command.

Detailed explanation of the at command

Let’s see how to use the at command .

Set up scheduled tasks

Use the at command to set up scheduled tasks at [- m] Time, the commonly used time format – HH:MM YYYY-MM-DD, in addition, it can also be set in the form of now +1 minutes in English.

# at 17:00 2020-11-11
 at> date >> /root/at.txt
 at>   date >> /root/at.txt
 at> 
 job 4 at Sat Nov 7 17:01:00 2020

View Scheduled Task

Use the -l option to view the scheduled tasks, and if you want to see specific commands, you can use the -c option. In addition, you can also use the atq command to view.

# at -l
 6 Sat Nov 7 17:13:00 2020 a root
 3 Wed Nov 11 17:00:00 2020 a root

 #atq
 6 Sat Nov 7 17:13:00 2020 a root
 3 Wed Nov 11 17:00:00 2020 a root

Remove scheduled task

The scheduled tasks that have not been executed can be deleted by at -d or atrm.

# at -d 3
 # atrm 6

Another advantage of using at to generate scheduled tasks is that offline management can be done.

The above is the scheduled task under linux – the detailed content of the scheduled task that is executed only once. For more information, please pay attention to other related articles on 1024programmer.com!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/scheduled-tasks-under-linux-scheduled-tasks-that-are-executed-only-once-linux-operation-and-maintenance/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索