JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

Use of Linux command at - set time to execute command only once

Author:JIYIK Last Updated:2025/04/08 Views:

This article mainly involves a knowledge point, which is the atd service. Similar to this service is the crond service. The functions of these two services can be similar to the two functional functions of javascript. Those who have learned javascript know that there are two functions in javascript, setInterval and setTimeout.

The function of setInterval is to execute code in a loop and set the interval time. This function is similar to the function of crond we are going to talk about here.

The function of setTimeout is to delay the execution of code for a certain period of time, and then stop executing it after the execution is completed. This function is similar to the function of atd which we will talk about next.

For crond and atd, these are two services. When we use them, we use their corresponding commands, namely crontab and at.

atd service enabled

at is a command that can execute a specified command once and then end the process. If at is needed, we need to enable the atd service. Generally, the Linux system has the atd service by default. The command to enable it is also very simple.

# service atd start
//Or use the following command
# /etc/init.d/atd start

How at works

In fact, the working method of at is to put the process corresponding to the command to be executed into its own process table. When we use the at command to generate a job to be run, at will store this job in the /var/spool/atd/ directory in the form of a document, and then the job will wait for the call of the atd service process to execute.

Generally, for the security of the server, it is necessary to set permissions for users. Not all users can perform at work. We can use the /etc/at.allow and /etc/at.deny files to restrict the use of at.

/etc/at.allow will allow users who use at to write to this file. Users in this file have the permission to use at. Of course, users who are not in this file do not have the permission to use at.

/etc/at.deny will not allow users who use at to write to this file. Users in this file do not have permission to use at. Of course, users who are not in this file have permission to use at.

Of course, the atd process works like this. When a user wants to use at, it will first look for /etc/at.allow. If the user is in this file, the user is allowed to use at. If not, the user is not allowed to use at. If /etc/at.allow does not exist, it will go back to look for the /etc/at.deny file. If the user is not in this file, the user is also allowed to use at. Of course, if both files do not exist, then by default only the root user can use at. In other words, even if these two files exist at the same time, there is a priority, and the atd process will give priority to the /etc/at.allow file.

In general Linux versions, since it is assumed that all users on the system can be trusted, the system usually retains an empty /etc/at.deny file.

at command format

The at command is very simple. Its basic format is as follows

# at [options] Time
Available options:
 -c: List the content of the actual command that follows.
 -l: at –l lists all at work routines of the user on the current system.
 -d: Can cancel a job in an at routine.
 -m: When the at work is completed, notify the user by email that the work has been completed.
 -v: List detailed information of the at work routine.
Time: Time format. Define when to perform this work.
         HH:MM At what hour and minute, perform this work at today's HH:MM time.
         HH:MM YYYY-MM-DD Perform this work at a certain hour and minute on a certain day of a certain year and month
         HH:MM[am|pm] [Month] [Date] Same as above, force it to be performed at a certain time on a certain day of a certain year and month!
       HH:MM[am|pm] + number [minutes|hours|days|weeks]
         means that it will be performed at a certain time "after adding a few more times".

Ok, let's look at an example. Delete the files in the /tmp directory 3 minutes from now.

# at now + 3 minutes //You should press Enter here
at> rm –rf /tmp/*
at> //You need to press ctrl+d here

In this way, after we wait for 3 minutes, we will find that the /tmp directory is empty.

Before the command is executed, if we do not want to execute the work command, we can delete it. Here we can use two commands: atq and atrm.

atq is equivalent to at -l to view all the working numbers of at. We can select one to delete

atrm is equivalent to at –d, which deletes the specified job, followed by the job number.

Use as follows

# atq
7 2016-04-29 15:53 ​​a root
//Or use at –l
# at –l
7 2016-04-29 15:53 ​​a root

We can see that the job number is 7. Next we can use atrm or at -d to delete the job.

# atrm 7
// or
# at –d 7

Then when we checked, we found that the job no longer existed.

Well, you can try to use other parameter options after the at command and see the displayed results. This will be very helpful for us to use at.

I hope this article is helpful to you.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Creating a signature from Hash_hmac() and Sha256 in PHP

Publish Date:2025/04/13 Views:107 Category:PHP

PHP has one of the best encryption functions for data security. Hash_hmac() The encrypt function is one of the most famous encryptors. We'll show you how to use hash_hmac and sha256 encryptors to create 安全签名 one that you can store i

Updating PHP 7.x to 7.4 on CentOS

Publish Date:2025/04/13 Views:131 Category:PHP

This article shows the steps to update the PHP version from 7.x version to 7.4 in CentOS. How to Update PHP from 7.X to 7.4 in CentOS Update operating system packages. yum update -y Check your PHP version in CentOS. php -v Prints a list of

Displays PHP configuration information on localhost

Publish Date:2025/04/13 Views:107 Category:PHP

phpinfo() is a built-in function in PHP which outputs all the information of PHP configuration on the local host. We have to phpinfo() create a PHP file with a simple function call. Sometimes, the file may not work properly and output a 404

Formatting a number as a dollar amount in PHP

Publish Date:2025/04/13 Views:75 Category:PHP

This article will cover different ways to format numbers as dollar amounts in PHP with examples. These include: number_format NumberFormatter::formatCurrency Regular expressions Manual format We'll also look at why money_format the function

Plotting Line Graph with Data Points in Pandas

Publish Date:2025/04/12 Views:65 Category:Python

Pandas is an open source data analysis library in Python. It provides many built-in methods to perform operations on numerical data. Data visualization is very popular nowadays and is used to quickly analyze data visually. We can visualize

How to Change the Data Type of a Column in Pandas

Publish Date:2025/04/12 Views:139 Category:Python

We will look at methods for changing the data type of columns in a Pandas Dataframe, as well as options like to_numaric , , as_type and infer_objects . We will also discuss how to to_numaric use downcasting the option in . to_numeric Method

Get the first row of Dataframe Pandas

Publish Date:2025/04/12 Views:78 Category:Python

This tutorial explains how to use the get_first_row pandas.DataFrame.iloc attribute and pandas.DataFrame.head() get_first_row method from a Pandas DataFrame. We will use the following DataFrame in the following example to explain how to get

Pandas Drop Duplicate Rows in DataFrame

Publish Date:2025/04/12 Views:75 Category:Python

This tutorial explains how to DataFrame.drop_duplicates() remove all duplicate rows from a Pandas DataFrame using the remove_by method. DataFrame.drop_duplicates() grammar DataFrame . drop_duplicates(subset = None , keep = "first" , inplace

Pandas DataFrame Delete a row

Publish Date:2025/04/12 Views:58 Category:Python

This tutorial explains how to pandas.DataFrame.drop() delete rows in Pandas using the method. import pandas as pd kgp_df = pd . DataFrame( { "Name" : [ "Himansh" , "Prateek" , "Abhishek" , "Vidit" , "Anupam" ], "Age" : [ 30 , 33 , 35 , 30 ,

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial