Skip to main content
Solved

Schedule a script to run daily

  • September 20, 2019
  • 4 replies
  • 14 views

Forum|alt.badge.img+10

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.

Best answer by mvu

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.

View original
Did this topic help you find an answer to your question?

4 replies

Hugonaut
Forum|alt.badge.img+15
  • Esteemed Contributor
  • 574 replies
  • September 20, 2019

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>

mvu
Forum|alt.badge.img+20
  • Jamf Heroes
  • 909 replies
  • Answer
  • September 20, 2019

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.


mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • 7881 replies
  • September 20, 2019

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.


Forum|alt.badge.img+10
  • Author
  • Valued Contributor
  • 108 replies
  • September 30, 2019

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings