I am in the process of writing a short script and need your help. The script is pretty simple. The aim is to first search and see if a specified process (processName=$4) is running. If it is, echo a string that states that it is running. If the specified process is not running, the script will execute /usr/local/bin/jamf policy -$5 $6 where jamfPolicyType=$5 and eventorIDName=$6.
#!/bin/sh
####################################################################################################
#
# DEFINE VARIABLES & READ IN PARAMETERS
#
####################################################################################################
#
# A HARDCODED VALUE FOR "processName," "jamfPolicyType" and "eventorIDName" CAN BE SET BELOW.
#
# A list of accepted process name values can be verified in Activity Monitor.
#
# Delete the double quotes and replace with the desired process name and/or event name, e.g.
# processName=Safari or eventorIDName=runSafariPolicy. For jamfPolicyType, pass "id" or "event."
#
# If this script is to be deployed via policy using the JSS leave the next line as is.
#
####################################################################################################
processName="Safari"
jamfPolicyType="ID"
eventorIDName="1"
####################################################################################################
#
# SCRIPT CONTENTS - DO NOT MODIFY BELOW THIS LINE
#
####################################################################################################
# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 4 AND, IF SO, ASSIGN TO "processName"
if [ "$4" != "" ] && [ "$processName" == "" ]
then
processName=$4
fi
# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 5 AND, IF SO, ASSIGN TO "jamfPolicyType"
if [ "$5" != "" ] && [ "$jamfPolicyType" == "" ]
then
jamfPolicyType=$5
fi
# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 6 AND, IF SO, ASSIGN TO "eventorIDName"
if [ "$6" != "" ] && [ "$eventorIDName" == "" ]
then
eventorIDName=$6
fi
# CHECK TO SEE IF THE SPECIFIED PROCESS IS RUNNING, THEN ECHO STATEMENT DEPENDING ON CONDITION
processRunning=$(pgrep -i $processName)
if [[ $processRunning != "" ]]
then
echo "$processName is running. Run Inventory Scan and run script again at next check-in."
else
echo "$processName is NOT running. Search for $jamfPolicyType triggered by $eventorIDName."
/usr/local/bin/jamf policy -$5 $6
fi
exit 0
Regardless of whether or not the specified process is running, the same echo string is returned.
"$processName is running. Run Inventory Scan and run script again at next check-in."
If it's not too much to ask, can someone please sift through the provided code and let me know where I've taken a wrong turn?