Schedule a script to run daily

joethedsa
Contributor II

I'm looking for a way to schedule the execution of a script at a specific time. I have deployed computers in our environment that have the same Deploy Studio image on it (this was Pre-Jamf). On the image, there is a scheduled restart that happens daily at 11pm- configured under Energy Saver system preferences pane. On some occasions, any open Applications sometimes will interrupt the restart. I have the script that closes all applications but need it to now run shortly before the 11pm restart. I know I can use Automator and iCal but would like to avoid that if at all possible so that I'm relying on Jamf.

1 ACCEPTED SOLUTION

obi-k
Valued Contributor III

I agree with the launchdameon route. Another way is to time your script in the policy (under General tab), but your results may vary as the computers check-in.

8a6ec64655964d6399c046bdf9567607

View solution in original post

4 REPLIES 4

Hugonaut
Valued Contributor II

Personally I'd use a launchdaemon to do this. Here is an example

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.yourscript.org</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/sh</string>
        <string>/Users/user/path/to/SCRIPT.sh</string>
    </array>
   <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>10</integer>
        <key>Minute</key>
        <integer>05</integer>
    </dict>
</dict>
</plist>
________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman
________________


Virtual MacAdmins Monthly Meetup - First Friday, Every Month

obi-k
Valued Contributor III

I agree with the launchdameon route. Another way is to time your script in the policy (under General tab), but your results may vary as the computers check-in.

8a6ec64655964d6399c046bdf9567607

mm2270
Legendary Contributor III

If you need it to run at a specific time, and not just a general timeframe, then a launchd job is really the best way to go. However, I'm not sure if a LaunchDaemon would be better than a LaunchAgent. As "agents" run as the currently logged in user, it might be possible to run your script in the user context. That will depend on whether anything in the script requires root privileges or not. If it doesn't need to invoke sudo or root commands, then an agent might give you better results.
You can test it out both ways to see.

joethedsa
Contributor II

Thanks to all for your input. Because the span of time was somewhat vast, I ended up using @mvu 's suggestion through Jamf.