At command on Linux (task scheduler)
The at command in Linux is used to schedule tasks in a similar way to cron, but in a simplified and non-recurring manner.
Its main application is to trigger tasks that must be performed only once.
Its format for scheduling tasks is more user-friendly and closer to human notation.
A feature of this program is that it performs tasks even if they have passed their execution time. It is useful on computers that are turned off frequently or when there is an interruption in the power supply.
Possible date and time notations can be entered in the following formats:
- HH:MM: HH for hour and MM for minute;
- midnight: for midnight;
- noon: for noon;
- teatime: for 16:00;
- MMDDYY: MM for month, DD for day and YY for year; MM/DD/YY
- ;
- DD.MM.YY;
-
- in a unit: Where n is the number of time units. The units can be minutes, days, hours, and weeks.
The most common options are:
- -l: List all tasks scheduled by at;
- -d N: Delete a specific task identified by number N;
- -f file: Indicates the file containing the commands to be executed.
See the examples:
Execute the commands specified in the comandos.txt file at breakfast time at 16:00.
Executes the commands specified in the comandos.txt file within 3 minutes.
Execute the commands specified in the comandos.txt file 3 hours from now tomorrow.
Another way to use at is to directly type the commands that will be executed at your command prompt:
In this example, at will open an “at>” command prompt to type the commands one per line. The “w” command that shows the connected users will be executed within 2 minutes by at.
To exit the at prompt, you must type Control-D.
The newly created job can be viewed with the “atq” command:
The results of the commands executed by at are sent by e-mail to the user who scheduled the task:
From [email protected] Fri Oct 18 14:33:00 2019 Subject: Output from your job 2 To: [email protected] Date: Fri, 18 Oct 2019 14:33:00 +0000 (UTC)
14:33:00 up 3 days, 11:49, 1 user, Load average: 0.04, 0.13, 0.11 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT Uira pts/0 ip-10-8-0-6 14:14 9.00s 0.08s& nbsp; 0.01s sshd: uira [priv]
Atq
The atq command lists the user’s pending jobs, and in the case of root, lists all jobs. The command provides the job number, date, time, queue, and user in the output.
Example:
Atrm
The atrm command removes a job from the task queue, identified by the job number.
Example:
All scheduled tasks are stored in files within the /var/spool/at/ directory.
Cat permissions
The at command also has two files responsible for securing access to the scheduler:
- /etc/at.allow
- /etc/at.deny
If the at.allow file exists, a particular user must have their login listed in its content to have express permissions to use at.
If at.deny exists, the logins listed in its content are prohibited from using at, and all other users are free.
If neither file exists, the use of at will only be allowed by superuser.
If the at.deny file is empty, all users are allowed to use at.
Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.
Did you like it?
Share