macOS CentOS – Making ‘at’ Work on macOS

atcentososx

I am working on a CentOS server and schedule a task with command at

# echo "touch a_long_file_name_file.txt" | at now + 1 minute
job 2 at Wed Oct 31 13:52:00 2018

One minute later,

# ls | grep a_long_file_name_file.tx
a_long_file_name_file.txt

the file was successful created.

However, if I run it locally on my macOS,

$ echo "touch a_long_file_name_file.txt" | at now + 1 minute
job 31 at Wed Oct 31 13:58:00 2018

Minutes later, if it failed to make such a file.

I checked the version of at on the CentOS server

AUTHOR:  
At was mostly written by Thomas Koenig, ig25@rz.uni-karlsruhe.de.  
2009-11-14                                             

In contrast, the macOS version

AUTHORS
     At was mostly written by Thomas Koenig <ig25@rz.uni-karlsruhe.de>.  The time parsing routines are
     by
     David Parsons <orc@pell.chi.il.us>, with minor enhancements by
     Joe Halpin <joe.halpin@attbi.com>.

BSD                            January 13, 2002                            

I found that at, atq, atrm are not of GNU coreutils.

$ ls /usr/local/opt/coreutils/libexec/gnubin/ | grep at
cat
date
pathchk
realpath
stat
truncate

How could I install the latest version of at on macOS and make it work?

Best Answer

Instead of updating at and the associated tools on macOS, lets try to make the default at on macOS work.

The at manual on macOS says (my emphasis):

IMPLEMENTATION NOTES

Note that at is implemented through the launchd(8) daemon periodically invoking atrun(8), which is disabled by default. See atrun(8) for information about enabling atrun.

Checking the atrun manual:

DESCRIPTION

The atrun utility runs commands queued by at(1). It is invoked periodically by launchd(8) as specified in the com.apple.atrun.plist property list. By default the property list contains the Disabled key set to true, so atrun is never invoked.

Execute the following command as root to enable atrun:

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

What I think may be happening here, and what is prompting your other at-related questions, is that you just haven't enabled atrun on your macOS installation.

On macOS Mojave, in addition to running the above launchctl command (with sudo), you will also have to add /usr/libexec/atrun to the list of commands/applications that have "Full Disk Access" in the "Security & Privacy" preferences on the system. Note that I don't know the security implications of doing this. Personally, I have also added /usr/sbin/cron there to get cron jobs to work (not shown in the screenshot below as this is from another computer).

enter image description here

To add a command from the /usr path (which won't show up in the file selection dialog on macOS), press Cmd+Shift+G when the file selection dialog is open (after pressing the plus-icon/button in the bottom of the window).

You do not need to reboot the machine after these changes. I have tested this on macOS Mojave 14.10.1.

Related Question