Mac OS X: at command not working

42

23

I am going to schedule a job by using at command. Here I tried the following command:

$ at now + 1 minute
echo 'Test at command'
<EOD>

I saw the job is scheduled by using at -l. However, I saw no echo out.

I guess that I may need to add user to at.allow file. I cannot find at.allow in my Mac (Snow Leopard). Not sure what I need to do to test this at command?

David.Chu.ca

Posted 2009-09-19T04:24:09.067

Reputation: 2 967

For Mac OS X Lion it's /var/at – Stefan Schmidt – 2011-10-12T19:44:07.447

I tried to read info from man at. It mentioned that "If the file _PERM_PATH/at.allow exists, only usernames mentioned in it are allowed to use at... If ... at.allow does not exists, _PERM_PATH/at.deny is checked,.." I am not sure what _PERM_PATH is. – None – 2009-09-19T04:41:10.983

In the case of Apple OSX Leopard, PERM_PATH for "at" is /usr/lib/cron. – Richard Hoskins – 2009-09-19T15:28:21.547

Answers

40

To enable the needed atrun daemon, as man atrun says, execute:

launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist

as root (e.g. via sudo). Once you've done that, /var/at/ will be the key directory (though the simplest way is to use at as root -- e.g., once again, by sudo!-).

Alex Martelli

Posted 2009-09-19T04:24:09.067

Reputation: 1 298

I should read the man pages first... Thanks! – polym – 2015-07-03T15:22:28.323

tested on yosemite, I had to wait 20 extra seconds before the job was actually executed (print to a file, do not echo because it won't show in the console) – ling – 2015-10-17T05:52:43.660

It's now May, 2019. This answer was correct for some older versions of macos, but it's not a complete answer for Mojave. There's a current, up-to-date answer on the U&L SE site.

– Seamus – 2019-05-30T11:08:04.613

1does this activation or atrun survive reboots? – Eric O Lebigot – 2011-06-30T09:38:29.910

According to the man page yes, but I haven't tried it. – Stefan Schmidt – 2011-10-12T19:38:32.760

1if /var/at/at.deny is empty you don't need to be root to queue at jobs, otherwise you can add your username to /var/at/at.allow. – Stefan Schmidt – 2011-10-12T19:42:22.583

I know that you need to be root to enable the atrun daemon, but you do not need to be root to run "at" commands. (Unless those commands require root.) – Richard Hoskins – 2009-09-19T15:24:13.927

13

In Snow Leopard you need to:

  1. Edit the /System/Library/LaunchDaemons/com.apple.atrun.plist, change the disabled child node from true -> false.

  2. Unload the current /System/Library/LaunchDaemons/com.apple.atrun.plist with:

    sudo launchctl unload -F /System/Library/LaunchDaemons/com.apple.atrun.plist
    

    Then load the edited version

    sudo launchctl load -F /System/Library/LaunchDaemons/com.apple.atrun.plist
    
  3. Test that it works with:

    echo blah | at now+1
    
  4. In case the echo fails for a different reason, you should be able to at least see the queue get cleared with:

    atq
    

Somantra

Posted 2009-09-19T04:24:09.067

Reputation: 320

1This is the only one that worked for me on OSX 10.10 Yosemite. – Colin Dean – 2014-11-08T20:24:30.750

5

I tried this on OS X Lion and it seemed to work.

First enable the atrun deamon:

launchctl load -w
/System/Library/LaunchDaemons/com.apple.atrun.plist

Then add [your username] to /var/at/at.allow.

When executed you will receive output at /var/mail/[your username]

I find that queued items with batch take a few minutes to get actually get executed.

chris838

Posted 2009-09-19T04:24:09.067

Reputation: 151

2

Others have replied about at being disabled on Mac OS X, and I don't know about that, but there is another problem: Where do you expect your echo command to print its message? On other Unix systems that I have used it does not print in the same shell window where you gave the at command. Remember that when the at job is run, you might not even be logged in any more.

Try to write something to a file instead, and see if that file appears at the right time.

Thomas Padron-McCarthy

Posted 2009-09-19T04:24:09.067

Reputation: 281

The man page states, that the output will be mailed to you. – Stefan Schmidt – 2011-10-12T19:39:48.203

@Stefan: Yes, and that worked well in the 1980's, when mail was handled locally on the same machine, but my experience (with other types of Unix than Mac OS X) is that nowadays you shouldn't expect to get any mail. – Thomas Padron-McCarthy – 2011-10-13T03:04:56.240

0

My installation of OS X (10.4) says in man at:

NOTE
     at, batch, atq, atrm are all disabled by default on Mac OS X.

Have you enabled atrun according to the instructions there?

Greg Hewgill

Posted 2009-09-19T04:24:09.067

Reputation: 5 099

I tried to find where is atrun in my Mac. From web, another option is to add user to at.allow. I could not find this file (at.allow) neither. – None – 2009-09-19T04:36:03.833