In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use the at command in Linux to execute the specified command sequence at a specified time, with a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
The user uses the Linux at command to execute the specified command sequence at a specified time. In other words, the command needs to specify at least one command and one execution time to run properly. The Linux at command can specify only the time, or it can be specified with the date. It should be noted that there is a systematic discrimination problem at a specified time.
For example, if the user now specifies an execution time: 3:20 in the morning, and the time when the Linux at command is issued is 20:00 the night before, on which day will the command be executed? If the user is still working before 3:20, the command will be completed by that time; if the user exits work before 3:20, the command will not be executed until the wee hours of the next morning. The following is the syntax format of the Linux at command:
At [- V] [- Q queue] [- f document name] [- mldbv] time
At-c job [job...]
At allows a rather complex set of time-specific methods, which actually extends the POSIX.2 standard. He can accept the time specified in hh:mm (hours: minutes) of the day. If that time has passed, it will be executed the next day. Of course, you can also use vague words such as midnight (late at night), noon (noon) and teatime (tea time, usually 4 p.m.) to specify the time. Users can also use a 12-hour timing system, that is, adding AM (morning) or PM (afternoon) after the time to indicate whether it is morning or afternoon. You can also specify a specific date for the execution of the command, in the format of month day (month day) or mm/dd/yy (month / day / year) or dd.mm.yy (day. Month. Year). The specified date must follow the specified time.
All of the above are absolute timing, but you can also use relative timing, which is good for arranging orders that will be executed in the near future. The specified format is: now + count time-units, now is the current time, time-units is the unit of time, here can be minutes (minutes), hours (hours), days (days), weeks (weeks). Count is the amount of time, whether it is days, hours, and so on. Another method of timing is to directly use today (today) and tomorrow (tomorrow) to specify the time to complete the command. Here are some examples to illustrate the specific usage.
[example 2] an order is specified to be executed at 5:30 this afternoon. Suppose the current time is 12:30, February 24, 1999, and 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 above commands express exactly the same meaning, so when arranging time, you are free to choose according to your personal preferences and specific circumstances. Generally speaking, the 24-hour timing method of absolute time can avoid timing errors caused by the user's own negligence, for example, the above example can be written as follows:
At 17:30 2-24-99
This is very clear, and others can understand it.
For Linux at commands, commands that need to be executed regularly are read and executed from standard input or from documents specified using the-f option. If the Linux at command is executed from a user shell using the su command, the current user is considered to be the executing user, and any errors and output are sent to that user. But if an email is sent, it will be received by the original user, that is, anyone who logs in to shell.
[example 3]
$at-f work 4pm + 3 days
The job in the document work is executed at 4: 00 p. M. three days later.
$at-f work 10am Jul 31
The jobs in the document work are performed at 10:00 on July 31st. In any case, * users can use this command. For other users, availability depends on two documents: / etc/at.allow and / etc/at.deny. If the / etc/at.allow document exists, only the users listed in it can use the Linux at command; if the document does not exist, the / etc/at.deny document is checked for existence, and none of the users listed in this document can use the 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 uses the specified queue. The queue name is made up of a single letter, and the legal queue name can be either amurz or Amurz. Queue an is the default queue for the Linux at command.
-m sends an email to the user who executes the Linux at command after the job ends.
-f file using this option will cause the command to be read from the specified file instead of from standard input.
An alias for the-l atq command. This command is used to view the sequence of scheduled jobs, which lists the jobs that the user is queued for and, in the case of a * * user, any work in the queue.
The syntax format of the command is as follows:
Atq [- V] [- Q queue] [- v]
An alias for the-d atrm command. This command is used to delete the sequence of commands to be executed. The syntax format is as follows:
Atrm [- V] job [job...]
-c sends the jobs listed on the command line to standard output.
[example 4] find any document in the system with the suffix txt and print it. After printing, send an email to the user foxy to notify the pickup. The appointed time is two o'clock in the morning on December 25th.
First type:
$at 2:00 12-25-99
Then the at > prompt appears and waits for the user to enter further information, that is, the sequence of commands that need to be executed:
At > find /-name "* .txt" | lpr
At > echo "foxy:All texts have been printed.You can take them over.Good daytime River" | mail-s "job done" foxy
Enter each line of instructions and enter. After entering any instruction sequence, use the key combination to end the input of the Linux at command. 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 often executed, it is generally used to write the sequence into a document and then process the document 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 uses the sequence of commands in the document, and the screen displays as follows:
Warning:command will be executed using / bin/sh.
Job 2 at 1999-12-25 02:00
/ sbin/service crond start / / start the service
/ sbin/service crond stop / / shut down the service
/ sbin/service crond restart / / restart the service
/ sbin/service crond reload / / reload the configuration
You can start this service automatically when the system starts:
At the end of the script / etc/rc.d/rc.local, add:
/ sbin/service crond start
Thank you for reading this article carefully. I hope the article "how to use at commands in Linux to execute the specified command sequence at a specified time" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.