Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Execute commands at a certain time UNIX
I was at work the other day and I was asked "How could I send an email to myself to remind myself to do X?" I was sure you could do that with Outlook (we use Windows), so i just played around and found it, not too hard. Then I thought to myself "I use OS X at home, we use freeBSD servers at work, there has to be a way to do this..."

After have a look around and asking a few people (thanx to johna for this), I was introduced to a command called at. This can be used to run any command at any time. You can also do this with cron, of course, but that's a pain. Use at as follows:
  % at HH:MM MM/DD/YYYY [hit enter]
For example, use at 08:45 08/25/2002 to set a job for 8:45am on Sunday the 25th of August, 2002. After that, just enter the commands you want run (follow each with enter). When you have finished the list of commands you want to run, press control-D.

HH:MM is the hours and minutes in 24 hour time, and MM/DD/YYYY is the month/day/year format of the date. For this to work, you have to be root or have your user name in a file called /var/at/at.allow (there is also an at.deny file).

There are many other was to use this command. If you are intrerested in the more advanced features, like how to run a command in X mins/hours/secs, read the man page (man at).

[Editor's note: I changed the syntax to reflect that you need to use a four-digit year to get a valid date.]
  • Currently 2.83 / 5
  You rated: 4 / 5 (6 votes cast)

Execute commands at a certain time | 8 comments | Create New Account
Click here to return to the 'Execute commands at a certain time' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
doesn't work
Authored by: ateles on Aug 23, '02 09:45:18AM

I included myself in at.allow, and then followed the instructions. But when after I enter the at comand I get the following error:

at: garbled time

Any ideas?

[ Reply to This | # ]
doesn't work
Authored by: beastie on Aug 23, '02 10:50:00AM

yeah, me too...

garbled time

after little experimentation discovered that thi works:

%-> sudo at 18:05 08/23/2002
ls -l
Job a0105f8c9.001 will be executed using /bin/sh

[ Reply to This | # ]
Four digit years...
Authored by: robg on Aug 23, '02 11:34:25AM
It turns out that at needs a four-digit year, not a two-digit year. I have revised the article to reflect the need to use "YYYY" instead of "YY". With the year formed in this manner, at works as expected.


[ Reply to This | # ]
Should work
Authored by: Accura on Aug 25, '02 07:34:42PM

Sorry, i shgould of picked this up, there are about 5 or 6 different way to write the time, its all in the man pages, also the best way to let all users use this with out adding all there inmes to at.allow is add a user who doesn;t exist to the at.deny

[ Reply to This | # ]
Easiest setup
Authored by: jmhaney on Aug 27, '02 08:14:06PM

sudo touch /var/at/at.deny

That will let any user have access to at. Just remember that if it has allow/deny, that's surely for some good reason...

[ Reply to This | # ]
at.allow doesn't work
Authored by: tcwatson on Aug 25, '02 04:02:26PM

checked out the man page and found this:

Traditional access control to at and batch via the files /var/at/at.allow and /var/at/at.deny is not implemented.

The date on the man page is 1993 though.

[ Reply to This | # ]
at.allow doesn't work (yeah it does)
Authored by: wjc on Oct 16, '02 09:40:31AM

it does work.

2 ways to do it:
sudo pico /var/at/at.allow, enter your username and save file
sudo touch /var/at/at.deny (from another post here)

either way, you'll get access to at

[ Reply to This | # ]
Execute commands at a certain time
Authored by: ygor on Sep 06, '03 09:04:19PM
There is one additional piece to this puzzle:
Look here:
You need to edit /etc/crontab to enable "at"

[ Reply to This | # ]