Posted on 04-11-2024 06:26 AM
Hey Jamf peoples.
Is there a way to get jamf to run a local script without waiting to see the results of the script?
I've written up a pretty basic Jamf Helper script to aide with encouraging/forcing users to restart their computers. Because I set a long time out on the jamf helper window, Ideally I'd echo a script locally to the computer and then have Jamf start the script and immediately exit the policy. When I test using an event trigger, the policy doesn't doesn't complete on Jamf's side until the local script resolves.
Is this possible without something like a launch daemon or launch agent?
This is basically what I was trying to do:
#!/bin/bash
#variables
scriptPath="/Library/myOrg/restart.sh"
directoryPath=$(dirname $scriptPath)
mkdir -p $directoryPath
touch $scriptPath
echo '
#!/bin/bash
orgIcon="/Users/Shared/MyOrgLogo.icns"
helper=/Library/Application\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper
date1=$(date "+%y%m%d")
pmDate=$(date "+%m/%d/%y")
shutdownDate=$(echo "$date1""2200")
userResponse=$("$helper" \
-windowType hud \
-lockHUD \
-title "Restart Required" \
-heading "Restart Required" \
-icon "$orgIcon" \
-button1 "Tonight" \
-button2 "Now" \
-description "Your computer has not restarted in over 10 days. Would you like to restart now or schedule your computer to restart at 10 PM tonight?" \
-timeout 7200 \
-defaultButton 2 \
)
#echo $userResponse
if [[ $userResponse == "2" ]]; then
"$helper" \
-lockHUD \
-windowType hud \
-title "Restart Required" \
-heading "Restart Required" \
-icon "$orgIcon" \
-description "Your computer will restart in 60 seconds. Please save any important work now!" \
-timeout 60
shutdown -r now
elif [ $userResponse == "0" ]; then
pmset schedule wake "$pmDate 21:59:45"
shutdown -r "$shutdownDate"
"$helper" \
-windowType hud \
-title "Restart Required" \
-heading "Restart Required" \
-icon "$misdIcon" \
-description "Your computer will restart at 10 PM. Please make sure to save any important work before leaving for the day" \
-button1 "Ok" \
-defaultButton 1
fi
' > $scriptPath
chown root:wheel "$scriptPath"
chmod 755 "$scriptPath"
bash $scriptPath & exit
Solved! Go to Solution.
Posted on 04-30-2024 03:21 PM
in case anyone comes back here looking for this answer:
$scriptPath </dev/null >/dev/null 2>&1 & disown
Worked for what I was trying to do
Posted on 04-11-2024 06:52 AM
try a subshell?
($scriptPath) &
exit
Posted on 04-11-2024 12:41 PM
That and so much more cleaner integration:
Posted on 04-30-2024 03:21 PM
in case anyone comes back here looking for this answer:
$scriptPath </dev/null >/dev/null 2>&1 & disown
Worked for what I was trying to do