In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 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 arrange tasks, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
When you want a command or script to run at a particular time, you don't need to hover your finger on the keyboard and wait for the enter key to be pressed, or sit at your desk at a specific time. Instead, you can set the task through the at command. In this article, we will examine how to use at to schedule tasks, how to choose exactly when a task wants to run, and how to use at to see which tasks are scheduled to run.
At vs cron
For those who use cron to schedule tasks on Linux systems, the at command is similar to cron because you can schedule tasks at selected times, but cron is used for jobs that run regularly-even once a year. Most cron jobs are set to run daily, weekly, or monthly, but you can control how often and when.
The at command, on the other hand, is used for tasks that run only once. Want to restart the system at midnight? No problem, as long as you have the appropriate permissions, at can do this for you. If you want the system to restart at 2 a.m. Every Saturday, use cron instead.
Use at
The at command is easy to use, just a few things to remember. A simple example of using at looks like this:
$at 5:00PMat > date > > thisfileat >
When entering at and when the command should be run, at prompts you to run the command at the set time (in this case, the date command). Enter ^ D (Ctrl + d) to complete the request.
Suppose we set the at command before 5 p.m., then the date and time will be added to the end of the file named thisfile at 5 p.m. That day. Otherwise, the command will run at 5 p.m. The next day.
When interacting with at commands, you can enter multiple commands. If you want to run multiple commands at the same time, simply enter multiple command lines:
$at 6:22warning: commands will be executed using / bin/shat > echo first > > thisfileat > echo second > > thisfileat >
In the above command, we used a normal user account to add some simple text to the files in the user's home directory. If you run these commands after 6:22, the commands will run the next day, because 6:22 means 6:22 If you want to run at 6:22 in the afternoon, use 6:22 PM or 18:22. 6:22 PM can also work in this way.
You can also schedule commands to run on a specified date or time by using at, such as 10:00AM April 15 2021 or noon + 5 days (run at noon within 5 days from today). Here are some examples:
At 6PM tomorrowat noon April 15 2021at noon + 5 daysat 9:15 + 1000 days
After specifying the command to run and pressing ^ D, you will notice that the at command assigns a job number to each request, which will be displayed in the job queue of the at command.
$at noon + 1000 dayswarning: commands will be executed using / bin/shat > date > > thisfileat > job 36 at Tue Dec 27 12:00:00 2022 & 2exit 1} date > > thisfile
Note that the command shows that it will first test whether you can enter the user directory through the cd command. If not, the job exits with an error. If possible, run the command specified in at. It treats the command as "enter / home/shs or exit and display an error".
Run the job as root
To run the at job as root, simply use sudo with your at command, as follows:
$sudo at 8PM [sudo] password for shs:warning: commands will be executed using / bin/shat > reboot nowat > job 37 at Wed Apr 1 16:00:00 2020
Notice that the task for root is displayed in the queue with root as the executor.
35 Mon Apr 6 12:00:00 2020 a shs36 Tue Dec 27 12:00:00 2022 a shs37 Wed Apr 1 20:00:00 2020 a root bin/trymeat >
Prohibit the use of at commands
The / etc/at.deny file provides a way to prohibit users from using the at command. By default, it may contain a list of disallowed accounts, such as ftp and nobody. You can use the / etc/at.allow file to do the opposite, but usually only the at.deny file is configured.
Thank you for reading this article carefully. I hope the article "how to use at commands to arrange tasks in Linux" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow 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.