1

I've written a Python script that I need to execute at a certain time after another script runs. I found the at command, and after a bit of digging, I tried the following (broken into multiple lines for readability):

/private/var/folders/w9/6q0rjl6n4yv859fpxbg4123w0000gn/T/S10/fm-git.py
--filename chiv-lib --repository /Users/chuck/Projects/chivalry/chiv-lib/
--path Chivalry/ --comment "test" | at 2:52pm

This ran the script immediately. So I tried

at 2:53pm
> /private/var/folders/w9/6q0rjl6n4yv859fpxbg4123w0000gn/T/S10/fm-git.py
> --filename chiv-lib --repository /Users/chuck/Projects/chivalry/chiv-lib/
> --path Chivalry/ --comment "test"
> ^D

But the time came and went and the script didn't execute. After the above, at -l outputs the following:

13  Mon Nov 27 02:53:00 2017
12  Mon Nov 27 14:52:00 2017

This is on macOS High Sierra. Is at the right utility for this? If so, how can I get it to do what I want here?

muru
  • 69,900
  • 13
  • 192
  • 292
Chuck
  • 475
  • 4
  • 13
  • It uses `fmsadmin`, the administration utility for FileMaker Server, to back up a served file, move it to a particular folder, create an XML report of the changes since the last commit, and commits it to the local repository and pushes the changes to the master. The most obvious indication that it's not working is that the Python calls an AppleScript that uses interface scripting to create the XML report. You can find both the Python and AppleScript scripts at https://github.com/chivalry/fm-git, but it's *definitely* not executing in the second case, and doing so immediately in the first. – Chuck Nov 27 '17 at 00:49
  • Note also … you can do `echo /private/…foo | at 2:52pm` — the `echo` is important. – BRPocock Nov 28 '17 at 05:05
  • Related: https://unix.stackexchange.com/questions/478823 – Kusalananda Oct 31 '18 at 10:00
  • Late to the party, but if you'd like to run the 'at' command the same way you'd run the `sleep` command whilst using a specific time instead of duration, then you set the following (which I use myself) in your shell's _rc_ file: `at() {sleep \`datediff $(date +%H:%M:%S) $(sed -r 's/([0-9]{2})([0-9])/\1:\2/' <(echo $1)) | sed -r 's/s$//'\`}` – Example: `at 15:10; ls` or `at 1510; ls` – Faxopita Mar 29 '23 at 14:52
  • Improved: `at() {[[ -n \`echo $1 | grep -o --perl "^\d{2}:?\d{2}\b"\` ]] && { HM=\`sed -r 's/([0-9]{2})([0-9])/\1:\2/' <(echo $1)\`; sleep \`[[ "$HM" > "$(date +%H:%M:%S)" ]] && datediff -f %S $(date +%H:%M:%S) $HM || datediff -f %S $(datediff -f %H:%M:%S $HM $(date +%H:%M:%S)) 24:00\`; } || { echo "Usage: at hh[:]mm && command"; (exit 1); }}` – Faxopita Mar 31 '23 at 13:59

1 Answers1

2

Let's see, on Mac OS X (as this hardware is too old to run macOS) plus with myat because I can never remember the date format at wants...

$ date
domingo, 26 de noviembre de 2017, 16:34:12 PST
$ myat 16:36
touch $HOME/nananananananananananananananana-atran
job 2 at Sun Nov 26 16:36:00 2017
$ atq
1       Wed Mar  9 08:00:00 2016
2       Sun Nov 26 16:36:00 2017
$ 

... why is there a job from 2016 hanging around??

$ date
domingo, 26 de noviembre de 2017, 16:36:33 PST
$ atq
1       Wed Mar  9 08:00:00 2016
2       Sun Nov 26 16:36:00 2017
$ 

Uhhhh...maybe the man page for at will help?

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 infor-
     mation about enabling atrun.

Meanwhile over in atrun(8) we find...

 Execute the following command as root to enable atrun:
       launchctl load -w
       /System/Library/LaunchDaemons/com.apple.atrun.plist

Gosh. Let's try that...

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

And then we wait like a minute or two...

$ atq
$ ls *atran
nananananananananananananananana-atran
$ 

Looks good once you turn it on (warning may drain battery or precious cpu slices...)

thrig
  • 34,333
  • 3
  • 63
  • 84