15

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?

5

2 Answers 2

37

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.

6
  • Seems to work in 11.0 / Big Sur also, should others be looking in the future.
    – flip
    Jan 5, 2021 at 19:34
  • Excellent instructions. Worked for me on 10.15.7 / Catalina. The "Full Disk Access" was the gotcha for me.
    – James
    May 4, 2021 at 11:58
  • That security setting is a real gotcha! Especially since older answers to the same question do not include it (as, presumably, it was not needed on older OSXes). Jun 19, 2021 at 15:03
  • After doing all this, I had to output the result of my command to a file to see the results, in that file. I couldn't see the results in the standard output for some reasons.
    – Akhil Raj
    May 14, 2022 at 20:54
  • 1
    In Big Sur you will find it under /usr/libexec/atrun
    – DimiDak
    Aug 23, 2022 at 13:53
1

To add to Kusalananda correct answer, Adding terminal application to the list of applications that have "Full disk access" will cause the standard output of at jobs to be mailed to the user.

I'm sorry I couldn't comment on his answer. I registered to the site just to add the information above and I don't have permission to comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.