Schedule tasks using the ‘at’ command

Scheduling jobs is an essential part of administering Linux servers. We took a look at how to schedule jobs on Linux machine using the cron command earlier. Here’s an alternative to cron – at. The primary difference between the two is that when you schedule a task using cron it execute repeatedly without the need for rescheduling. With at, on the other hand, the scheduling of a task is only for a single execution. Both of these commands have their use, and I would suggest that you get a good understanding of them both.

Let’s look at how to schedule a task to execute only once using the at command. First make sure that the at daemon is running using a command like this:

# ps -ef | grep atd
root 8231 1 0 18:10 ? 00:00:00 /usr/sbin/atd

If you don’t see atd running start it with this command:

# /etc/init.d/atd start

Once the daemon has been started successfully you can schedule an at task using the two options -f, for the file to be executed, and -v, for the time at which it should be executed. So if you want to execute the shell script shellscript.sh at 6:30 PM you would run the following command:

# at -f shellscript.sh -v 18:30

Remember that with the at command the script shellscript.sh will execute at 6:30 PM and then the scheduling will disappear. So if this is not what you desire, you are better off using cron.

The at command is pretty clever in that it can take some orders in English if you like. For example, you can schedule jobs using the following syntax as well:

# at -f shellscript.sh 10pm tomorrow

# at -f shellscript.sh 2:50 tuesday

# at -f shellscript.sh 6:00 july 11

# at -f shellscript.sh 2:00 next week

g33kadmin

I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.