Being able to execute a Linux command at a later time is very important feature for systems Administrator. Job scheduling is taken care by two daemons: atd and crond. Atd manages jobs that run only ones while crond runs jobs at predefined times.
Used to schedule one-time job execution at predefined time.
Lets check if at command already installed on our system. (We are using CentOS 7.0)
#yum list installed at Loaded plugins: fastestmirror Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast Loading mirror speeds from cached hostfile * base: centos.mirror.iweb.ca * extras: centos.mirror.rafal.ca * updates: centos.mirror.rafal.ca Error: No matching Packages to list
As we can see at command is not installed. We will install it using yum package manager
#yum install at -y
We will also have to start at service
#service atd start
We can now schedule shell script test.sh to run 5 min from now
#at -f test.sh now + 5 min
Ways to express time with at
at 2:20 am – will execute at 2:20 am
at 16:30 tomorrow – will execute at 16:30 next day
at now + 5 hours – will execute 5 hours from now
at now + 5 min – will execute 5 minutes from now
at 4:00 6/14/16 – will execute on this time on this day
In this example we will create at job that will run test.sh 20 min from now. We will list it and then remove it. You will need to node the job number highlighted in red.
# at -f test.sh now + 20 min job 5 at Tue Mar 8 08:47:00 2016 # at -l 5 Tue Mar 8 08:47:00 2016 a root # ls /var/spool/at/ a000050172a5bb spool # at -d 5 # at -l # ls /var/spool/at/
All users allowed to use at command by default. This behaviour can be adjusted using files at.allow and at.deny. All we need to do is put username – one per line in allow or deny file.
Log for all at activities located under /var/log/cron