Posted on 08-09-2017 01:25 PM
Having issues with several packages, in particular Acrobat where users never seem to quit out. Working on a script to check for running app, upgrade if NOT running, present user with a notification if it is.
Have basic syntax down, but still running into issues. Anyone want to chime in on it and tell me what I'm missing? Have snippets taken from some of my other scripts and some from scripts found here on JamfNation, but missing something when sticking it all in together.
Basically, I'm caching the installer on all machines with a separate policy. Using a smart group detecting the cached installer, I then run the following script. It first checks to see if Acrobat is running. If NOT, proceeds to call a policy to install the cached package. If Acrobat IS running, asks user to save and quit (and run package) or allows them to cancel and it will simply repeat at the next policy check-in interval.
#!/bin/sh
#shorten path for JAMFHelper to abreviate following lines
JAMFHELPER="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
#determine if Acrobat is running:
IsAcrobatRunning=$(pgrep -l "Acrobat" | cut -c6-30)
if [ "$IsAcrobatRunning" = "AdobeAcrobat" ] ; then
echo "Detected running Acrobat instance, prompting user to quit and upgrade"
# Get the user's selection
RESULT=$JAMFHELPER -windowType hud -title Updates Required -heading Adobe Acrobat -description "There is a pending Adobe Acrobat security update. Please quit out of Acrobat now, as the installation of this software will fail if it detects a Acrobat running during the installation. Click OK to indicate that Acrobat has been quit and to upgrade now, Cancel will re-try in one hour. Thank you for your patience while we upgrade." -icon /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns -button1 "Cancel" -button2 "OK")
echo "jamf helper result was $RESULT";
if [ "$RESULT" == "0" ]; then
echo "Clicked OK, time to quit Acrobat!"
/usr/sbin/jamf policy -trigger InstallCachedAcrobat
exit 0
else
echo "user chose Cancel";
exit 1
fi
echo "Acrobat is not running, proceeding with upgrade"
/usr/sbin/jamf policy -trigger InstallCachedAcrobat
exit 0
Posted on 08-09-2017 02:44 PM
@Taylor.Armstrong What issues are you seeing?
Posted on 08-09-2017 03:03 PM
I think your RESULT line is missing a leading $( for example RESULT=$($JAMFHELPER ....)
and
-trigger should be -event
Posted on 08-09-2017 03:06 PM
I took a minute to test out your script, and found a few things that needed to be tweaked:
- There are two "if" statements, but only one closing "fi" statement
- The "RESULT=$JAMFHELPER ..." line has a closing paren but no opening paren. To run a command and capture the result it needs to be in the format result="$(cmd args)"
, but this looks like result=$cmd args)
. This is easier to see if you break the jamfHelper statement up over multiple lines for readability.
- The result check if [ "$RESULT" == "0" ]
should actually be if [ "$RESULT" == "2" ]
if testing for the OK button click.
It is easier to code and debug this on a local machine if possible, and then copy/paste the script up to the JSS when it is working.
I have made the recommended changes to your script and attache it here. It appears to be working on my machine, so hopefully it gets you closer at least.
#!/bin/bash
export PATH="/usr/sbin:$PATH"
JAMFHELPER="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
MESSAGE="There is a pending Adobe Acrobat security update.
Please quit out of Acrobat now, as the installation of this
software will fail if it detects a Acrobat running during
the installation. Click OK to indicate that Acrobat has been
quit and to upgrade now, Cancel will re-try in one hour.
Thank you for your patience while we upgrade."
# Determine if Acrobat is running
IsAcrobatRunning=$(pgrep -l "Acrobat" | cut -c6-30)
if [ "$IsAcrobatRunning" = "AdobeAcrobat" ] ; then
echo "Detected running Acrobat instance, prompting user to quit and upgrade"
# Get the user's selection
result=$("$JAMFHELPER" -windowType hud
-title "Updates Required"
-heading "Adobe Acrobat"
-description "$MESSAGE"
-icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
-button1 "Cancel"
-button2 "OK")
echo "User choice: $result"
if [ "$result" == "2" ]; then
echo "Clicked OK, time to quit Acrobat!"
jamf policy -trigger InstallCachedAcrobat
exit 0
else
echo "User chose Cancel"
exit 1
fi
else
echo "Acrobat is not running, proceeding with upgrade"
jamf policy -trigger InstallCachedAcrobat
exit 0
fi
Posted on 08-10-2017 08:23 AM
Thank you so much guys - think I'd just gotten pulled away from my desk too many times during the day, and my eyes were starting to cross staring at the code.
Only thing left to do now is to have the "OK" button also send a "kill" command to Acrobat if the user did not quit out, and think I've finally gotten past this one.
Posted on 08-10-2017 09:25 AM
I'm a big fan of @kitzy 's workflow: https://www.johnkitzmiller.com/blog/better-software-updates/