at(1) on the Mac

at is the command for scheduling things from the command line. To schedule a job, run at with the desired time and write the list of shell commands you want to run. The example below shows a one-line at job designed to run at 9 in the morning. Pressing CTRL-D exits the script declaration and confirms that the job is queued.

chris@MacMini-4% at 0900
sh /Users/chris/Sources/unixsetup/bin/backup_media.sh
job 4 at Sun Jan 17 09:00:00 2021

And it is disabled on the Mac. I discovered this last night because I scheduled a large file copy and it hadn’t worked when I looked in the morning. It fails silently. Here is the job list. Boo.

chris@MacMini-4% at -l
 2 Thu Jan 14 23:00:00 2021
 1 Fri May 29 12:00:00 2020

It would seem that on May 29th I scheduled something else. Whatever it was, it didn’t work either… Anyway it turns out this is documented in the atrun(8) manual page:

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

Well well. Anyway, I have command line scheduling working again. By the time I need it, I will have probably forgotten and be on a different Mac. By the way, my command line prompt says Mac mini-4. I don’t have 4 Mac minis. For some reason once a month, my Mac decides that it is clashing with another device on the network and renames itself. I suspect this is due to the Mac being on the wireless network and the wired network.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.