Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of at Command under linux

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge about "the usage of at command under linux". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

Linux at Command

The user uses the linux at command to execute a specified sequence of commands at a specified time. That is, the command needs to specify at least one command and one execution time to function properly. The linux at command can specify only the time, or both the time and the date. It should be noted that there is a systematic discrimination problem at a given time. For example, if the user specifies an execution time of 3:20 a.m. and the linux at command is issued at 20:00 the night before, what day is the command executed? If the user is still working before 3:20, then the command will be completed at this time; if the user exits the work state before 3:20, then the command will not be executed until the next morning. Here is the syntax for the linux at command:

at [-V] [-q queue] [-f file name] [-mldbv] time

at -c job [job...]

AT allows for a rather complex set of methods for specifying time, effectively extending the POSIX.2 standard. He can accept a hh:mm (hour: minute) time designation for the day. If that time has passed, it will be executed the next day. (4 p.m.)(5 p.m.)(6 p.m.)(6 p.m.)(7 p.m.)(8 p.m.)(8 p.m.)(9 p. m

Words to specify time. Users can also use a 12-hour clock system, which adds AM (morning) or PM (afternoon) to indicate whether it is morning or afternoon.

It is also possible to specify a specific date on which the command will be executed, in the format month day or mm/dd/yy or dd.mm.yy. months. year). The specified date must follow the specified time.

The above is absolute timing method, in fact, you can also use relative timing method, which is very useful for arranging orders to be executed soon. The specified format is: now + count time-units, where now is the current time and time-units are time units, which can be minutes, hours, days, weeks. Count is the number of days, hours, etc.

Another way to time a command is to use today and tomorrow directly to specify the time to complete the command. Here are some examples of how to use it.

[Example 2] Specify that a command be executed at 5:30 p.m. today. Assuming that the time is 12:30 p.m., February 24, 1999, the command format is as follows:

at 5:30pm

at 17:30

at 17:30 today

at now + 5 hours

at now + 300 minutes

at 17:30 24.2.99

at 17:30 2/24/99

at 17:30 Feb 24

The meaning of these commands is exactly the same, so when arranging the time, it is enough to choose freely according to personal preferences and specific circumstances. Generally, the 24-hour timing method of absolute time can avoid the occurrence of timing errors caused by the user's own negligence. For example, the above example can be written as:

at 17:30 2/24/99

This is clear and others can understand it.

For linux at commands, the commands that need to be timed are those that are read and executed from standard input or from documents specified with the-f option. Suppose the linux at command is converted from a command using su to a user shell

The current user is considered to be the executing user, and any errors and outputs are sent to this user. But if an email is sent, it will be received by the original user, i.e., whoever was in the shell at the time of login.

Example 3

$ at -f work 4pm + 3 days

Perform the assignment in the document work three days later at 4 p.m.

$ at -f work 10am Jul 31

Perform the assignment in document work at 10 a.m. on July 31.

In any case, *** users can use this command. For other users, the availability depends on two documents: /etc/at.allow and/etc/at.deni.

If the/etc/at.allow document exists, only the users listed in it can use the linux at command; if it does not exist, the/etc/at.deny document is checked

None of the users listed in this document can use this command. If neither document exists, only *** users can use the command; an empty/etc/at.deny document means that all users can use the command, which is also the default state.

The parameters in the command are described below.

-V Prints the standard version number to standard error.

-q queue Use the specified queue. Queue names are composed of a single letter, legal queue names can be a-z or A-Z. A queue is the default queue for linux at commands.

-m After the job ends, send an email to the user who executed the linux at command.

-f file Using this option causes the command to read from the specified file instead of standard input.

-l An alias for the atq command. This command is used to view the scheduled job sequence. It will list the jobs that the user has queued and, in the case of *** users, any jobs in the queue.

The syntax of the command is as follows:

atq [-V] [-q queue] [-v]

-d An alias for the atrm command. This command deletes the sequence of commands specified to be executed. The syntax is as follows:

atrm [-V] Job [Job...]

-c Send jobs listed on the command line to standard output.

[Example 4] Find any document in the system with a suffix of txt and print it. After printing, foxy sends out an email notification to the user to pick up the file. the appointed time is 2 am on december 25.

First type:

$ at 2:00 12/25/99

The system then presents the at> prompt, waiting for the user to enter further information, i.e. the sequence of commands to be executed:

at> find / -name "*.txt"|lpr

at> echo "foxy:All texts have been printed.You can take them over.Good day! River" |mail -s "job done" foxy

After entering each command line and then enter, use the key combination to end the linux at command after any sequence of commands has been entered. The following message will appear on the screen:

warning:command will be executed using /bin/sh.

job 1 at 1999-12-25 02:00

Remind the user which shell will be used to execute the command sequence.

In fact, if the command sequence is long or frequently executed, it is usually written to a document and then processed as input to the linux at command. It's not easy to make mistakes.

[Example 5] The above example can be modified as follows:

Write the command sequence to the document/tmp/printjob with the following statement:

$ at -f /tmp/printjob 2:00 12/25/99

In this way, the linux at command will use the command sequence in the documentation, and the screen will look like this:

Warning:command will be executed using /bin/sh.

job 2 at 1999-12-25 02:00

The requested URL/sbin/service crond/was not found on this server.

/sbin/service crond stop //close service

The requested URL/sbin/service crond/was not found on this server.

The requested URL/sbin/service crond reload /was not found on this server.

This service can also be started automatically when the system is started:

At the end of the script/etc/rc.d/rc.local add:

/sbin/service crond start

The above is a use case for the linux at command.

"Linux at command usage" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report