The at command is used to schedule a one-time task at a specific time. batch command is used to schedule a one-time task to be executed when the systems load average drops below 0.8.
01. Installing at :
It is installed by default in almost cases, but some times it may be missed (at and batch within same package), so we will install it to make sure it is OK.
yum -y install at
02. Running atd service :
systemctl enable atd systemctl start atd systemctl status atd
03. Scheduling at jobs:
To schedule a one-time job at a specific time, type the command at time, where time is the time to execute the command.
batch don’t take any parameter , it will run only if system load average is below 0.8 , it may be immediately or after minutes or hours ,…
The time can be one of the following formats :
HH:MM format ,
example: at 22:00 OR: at 10:00 pm
month-name day year format ,
example: at January 15 2018
MMDDYY, MM/DD/YY, or MM.DD.YY formats,
example: at 011518 is the same as (January 15 2018)
now + time — time is in minutes, hours, days, or weeks, example: at now + 5 minutes , at now + 1 weeks
Examples: (press Enter after each command line, CTRL+D when finish)
[[email protected] ~]# at now + 5 minutes at> touch at.after5min at> <EOT> job 8 at Sun Apr 23 03:02:00 2017 [[email protected] ~]# at 3:10 am at> touch at.am at> <EOT> job 9 at Sun Apr 23 03:10:00 2017 [[email protected] ~]# atq 8 Sun Apr 23 03:02:00 2017 a root 9 Sun Apr 23 03:10:00 2017 a root [[email protected] ~]# batch at> touch batch.at at> <EOT> job 13 at Sun Apr 23 03:23:00 2017 [[email protected] ~]#
To list scheduled jobs: atq
it will be in format: ID Time a/= USER for both at and batch
a means scheduled.
= means there was something wrong.
successfully jobs will not shown.
Users can only view their own jobs. If the root user executes the atq command, all jobs for all users are displayed.
To remove a job: at -r ID OR atrm ID where id is the number for each job, you can get it using atq , from the example: it is 2 jobs with id 8 , 9 .
at -r 9 OR atrm 9 will delete the job number 9.
To read tasks from a file: use -f FileName option
create a file and write your command each at separate line,
it is useful with scripting.
echo "touch file.txt" > atfile
at now + 5 minutes -f atfile
I used touch command for testing as it easy to see if it working by listing current directory by ls command and see if the files is created , but you are free to use any command lines as many as you want.
I hope it was simple, comments are available if any help needed.