The Linux `at’ command

Written by James McDonald

June 9, 2010

Cron does repeating jobs at runs one off jobs. So can be handy

You need the `at’ package

yum install at

The at daemon must be running

ps -ef | grep atd
root      2496     1  0 Mar18 ?        00:00:00 /usr/sbin/atd

If not. Use chkconfig (redhatian) or update-rc.d (debian) to set it to start automatically

# add it (This is how you would get it running with a Redhat based system such as Fedora)
chkconfig atd --add 
chkconfig atd on
chkconfig --list atd
atd            	0:off	1:off	2:off	3:on	4:on	5:off	6:off

# then as root start it
service atd start

Using the at command add the job. The thing about this, to my mind is that you can’t specify a command with arguments as far as I am aware so you have to wrap all the commands in a script and point at to it using the -f parameter

at -f /usr/local/bin/service-start 7am tomorrow
at -f /usr/local/bin/service-stop 2pm tomorrow

Use atq to check to see if the job was added correctly

2	2010-06-10 14:00 a root
1	2010-06-10 07:00 a root

You can list the contents of the at job using at <jobNum> -c

at 1 -c 

This is what at 1 -c spits out on my CentOS 5.x system

# atrun uid=0 gid=0
# mail   myuser 0
umask 22
HOSTNAME=myhostname.domain.local; export HOSTNAME
SHELL=/bin/bash; export SHELL
USER=root; export USER
LS_COLORS=no=00:fi=00:di=00\;34:ln=00\;36:pi=40\;33:so=00\;35:bd=40\;33\;01:cd=40\;33\;01:or=01\;05\;37\;41:mi=01\;05\;37\;41:ex=00\;32:\*.cmd=00\;32:\*.exe=00\;32:\*.com=00\;32:\*.btm=00\;32:\*.bat=00\;32:\*.sh=00\;32:\*.csh=00\;32:\*.tar=00\;31:\*.tgz=00\;31:\*.arj=00\;31:\*.taz=00\;31:\*.lzh=00\;31:\*.zip=00\;31:\*.z=00\;31:\*.Z=00\;31:\*.gz=00\;31:\*.bz2=00\;31:\*.bz=00\;31:\*.tz=00\;31:\*.rpm=00\;31:\*.cpio=00\;31:\*.jpg=00\;35:\*.gif=00\;35:\*.bmp=00\;35:\*.xbm=00\;35:\*.xpm=00\;35:\*.png=00\;35:\*.tif=00\;35:; export LS_COLORS
MAIL=/var/spool/mail/root; export MAIL
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin; export PATH
INPUTRC=/etc/inputrc; export INPUTRC
PWD=/usr/local/bin; export PWD
LANG=en_US.UTF-8; export LANG
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass; export SSH_ASKPASS
SHLVL=1; export SHLVL
HOME=/root; export HOME
LOGNAME=root; export LOGNAME
LESSOPEN=\|/usr/bin/\ %s; export LESSOPEN
OLDPWD=/root; export OLDPWD
cd /usr/local/bin || {
	 echo 'Execution directory inaccessible' >&2
	 exit 1
${SHELL:-/bin/sh} << `(dd if=/dev/urandom count=200 bs=1 2>/dev/null|LC_ALL=C tr -d -c '[:alnum:]')`


/usr/local/bin/servicerun start


  1. cwraig

    I often use sleep to run stuff later as in to turn my computer off in an hour (like a snooze timer)

    sleep 3600 && init 0

    This waits 3600 seconds (or 1 hour) and then shutsdown.

    • james

      Good tip at is probably overkill for something you just want to run in a little while.

      Thanks Craig



  1. Linux `at’ command – Part II – The Telarah Times - [...] I am looking at the Linux at command again. [...]

Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…