05-03-2024 05:59 AM - edited 05-03-2024 06:01 AM
Hi there,
I have a script that runs once on each machine in our macOS fleet. The script essentially creates a launchdaemon that runs a script that kills and restarts jamf binaries on machines once a day to mitigate the jamf checkin issues (no we do not have a force restart schedule).
Issue I'm noticing is that some devices (about 50) even though they have the launchdaemon loaded it doesn't seem to be restarting their Jamf binaries. My thinking is it may be the script that is not working as intended.
I intend for the restart script to be re-ran everyday on the local machine but some devices have not checked in for weeks now.
#!/bin/sh
cat << 'EOF' > /private/var/tmp/JamfRestart.sh
#!/bin/sh
sudo killall jamf
sleep 10
sudo jamf policy
EOF
chmod 755 /private/var/tmp/JamfRestart.sh
chown root:wheel /private/var/tmp/JamfRestart.sh
cat << EOF > /Library/LaunchDaemons/com.JamfRestart.plist
<?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>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/usr/local/sbin:/opt/local/bin</string>
</dict>
<key>Label</key>
<string>JamfRestart</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>/private/var/tmp/JamfRestart.sh</string>
</array>
<key>RunAtLoad</key>
<false/>
<key>StartInterval</key>
<integer>86400</integer>
</dict>
</plist>
EOF
chmod 644 /Library/LaunchDaemons/com.JamfRestart.plist
chown root:wheel /Library/LaunchDaemons/com.JamfRestart.plist
launchctl load -w /Library/LaunchDaemons/com.JamfRestart.plist
Posted on 05-03-2024 06:19 AM
@_aDiedericks You really don't want to put scripts you need to be on the Mac long term in /private//var/tmp. A better location would be something like "/Library/Management/MyOrgName" or "Library/Application Support/MyOrgName"
05-03-2024 06:21 AM - edited 05-03-2024 06:21 AM
Thanks, I'll onboard this info on my end and make the adjustments. Do you know how I can log the output of the script's last run? Referring to within the "JamfRestart.sh" script.
Posted on 05-03-2024 06:28 AM
You'd need to put code into your script that would write to a file in /var/log. Here's a useful example of that: https://community.jamf.com/t5/jamf-pro/script-log-to-text-file/m-p/137935/highlight/true#M127017
Posted on 05-07-2024 12:21 AM
Thanks. Got the log working.
Posted on 05-03-2024 07:21 AM
JAMF Checkin issue? is there a PI for this? Anyone else seeing this?
Posted on 05-07-2024 12:23 AM
It's not a general issue. Some people have it, some dont. I think it's due to a policy/script running during jamf policy update on devices that doesn't exit or complete that causes jamf binaries to hang indefinitely until the process is killed or device is restarted.