How to schedule Linux commands with 'at'
Utility at very easy to use. Users only need to give time and date as command line parameters, then enter one or more commands to execute.
If you have to manage a 'busy' server, you have to wait for an appropriate time to restart the server (ie when people don't use it). This appropriate time is probably at dawn. But this is inconvenient! Does the administrator have to wake up early just to restart his server? With Linux, automating such a simple task is easy with the 'at' utility .
This utility is very easy to use. Users only need to give time and date as command line parameters, then enter one or more commands to execute.
On a server, it is useful to have such a program because users often want the server to perform unattended actions. But even on desktops, at can also be a very convenient tool. For example, suppose you download a very large file. You can schedule your PC to turn off late at night. In addition, users can request at remind them of what to do. Many actions can be scheduled with the appropriate command line tools and options.
Schedule tasks with utilities at Linux
- How to install at different Linux distributions
- Enable the auto-start daemon at
- How to specify the date and time to schedule at commands
- How to use the at command
- View and / or delete scheduled jobs
- Schedule at to run graphics applications
How to install at different Linux distributions
On Debian or Debian-based distributions, run:
sudo apt install at
On Fedora, run:
sudo dnf install at
To install at on Arch Linux, enter the command:
sudo pacman -S at
And, on openSUSE, enter the command:
sudo zypper install at
Enable the auto-start daemon at
Some distributions will automatically activate daemon boot at boot time. But some other distributions do not. Please check with:
systemctl is-enabled atd.service
If the result is 'disabled', then enable it with:
sudo systemctl enable atd.service
And start the daemon:
sudo systemctl start atd.service
How to specify the date and time to schedule at commands
Users can use one of the following forms.
1. Run the command after the specified number of minutes, hours, days or weeks.
at now + 10 minutes at now + 10 hours at now + 10 days at now + 10 weeks
2. Run at an exact time:
at 23:10
If it is 12:00, and you run:
at 11:00
The order will run tomorrow, at the time specified.
3. Run at the specified time and date:
at 12:00 December 31
Other ways to determine the time and date can be found in the online utility manual. (link reference: https://linux.die.net/man/1/at)
How to use the at command
As you can see, after specifying the scheduled time, a command prompt like the following image will appear:
Here, users only need to enter the commands they want to run. They will be executed under the current user name. Enter the command you want to run at a specified time and press Enter. If you want to run the next command, repeat the same process. When done, press Ctrl + D. will be displayed when the keys are pressed, followed by the time the command (s) will be executed.
If you want to run commands that require root access, do not use sudo. Remember, the command will run without supervision, so sudo will not work because no one has entered the password. Instead, first log in as the root user:
sudo -i
And then use the at command as usual. Now, all commands will be executed with root privileges, instead of regular users.
After scheduling the order, enter:
exit
This command will log you out from the user root account.
In the example in this screenshot, the shutdown is scheduled for two minutes. Users can adjust it to suit their own needs.
If the computer is turned off before a scheduled job has a chance to run, that task will run at the next boot (if the time is set for it to be over). For example, if the work schedule is scheduled at 3 pm, turn off the computer at 2 pm and turn on the power at 4 pm, the work will run at 4 pm.
View and / or delete scheduled jobs
Users can view jobs ordered by order:
atq
Or command:
at -l
To see which commands are scheduled on a job, use the prefix number of the job.
at -c 22
The final output lines will show the user the scheduled commands.
To delete a job, use its prefix number as follows:
atrm 22
Schedule at to run graphics applications
First, find the current display variable value:
echo $DISPLAY
Usually, it will be : 0.
Schedule to run at. In the at prompt, set the DISPLAY variable to the previous value ( export DISPLAY =: 0 ) and run the desired graphics application.
The commands used in the previous screenshot will result in the following results.
Now, the graphics application will prompt users for an important job better than the phone alarm.
Use at very easy. The harder part is finding a creative way to perform an action you desire. But you can do whatever you want, like starting to download, close the program, put the computer on standby, etc.
Hope you are succesful.
You should read it
- 14 interesting Linux commands in Terminal
- Basic Linux commands everyone needs to know
- 20+ essential Linux security commands
- How to use the Linux command line on Android with Termux
- Top 10 examples of Netstat commands on Linux
- 15 Tar commands should try in Linux
- How to run 2 or more Terminal commands at the same time on Linux
- 11 df commands in Linux (with example)
- Kali Linux commands from AZ and commonly used commands
- 12 things Linux is easier to do in the command line than graphical software
- 7 commands to manipulate the most basic files and folders everyone must know
- How to copy (and paste) files and folders from the Linux command line
Maybe you are interested
Compare useEffect, useLayoutEffect and useEffectEvent in React 30 camera apps that collect user data, you should remove immediately Call the function by pointer in C ++ CAST function in SQL Server 35 questions from writer Marcal Proust tell all about you In your opinion, should you clean or wash after going to the toilet? The answer will startle you