Running a script locally on the screen and exiting the policy immediately

kbreed27
Contributor

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

 

1 ACCEPTED SOLUTION

kbreed27
Contributor

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 

View solution in original post

3 REPLIES 3

jamf-42
Valued Contributor II

try a subshell? 

($scriptPath) &
exit

 

efil4xiN
Contributor II

That and so much more cleaner integration:

here 

kbreed27
Contributor

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