Skip to main content
Solved

Parameter Issue in Script When Used in Policy


sepiemoini
Forum|alt.badge.img+19

Greetings, all! I have a pretty (what I believe to be) nifty script which checks to see if specified processes or applications are running before executing a policy.

My first really application for this is to be used for Office 2016 updates. I would pass the five Office applications (Excel, OneNote, Outlook, PowerPoint and Word) as the processNameX variables where X is an incremental integer beginning at 1. I also pass the jamfPolicyType and eventorIDName variables in the policy itself with "-id" and "841" respectively. The 841 integer represents the policy that I have created which simply installs the package when it is called on. I have a similar script but it only has 1 processName variable/parameter and it works flawlessly both locally and when used in the JSS. I made a few modifications, all of which were pretty simple, to accommodate for the added parameters being passed. This script runs beautifully when I run it locally and in the JSS when I pass the variables in the script itself but throws an error when I use the parameters at the policy level. Specifically there is an error with the eventorIDName parameter. The following error is received:

No policies were found for the "/0" trigger.

To correct this, I have to pass the -id associated with the policy I would like to run in the script. When I do this, it works with no errors whatsoever. I have also tried running other policy -id as well (like 1 for the update inventory default) all of which yield the same above error. For reference, please find my screen capture of the script details below.

Any thoughts? What am I doing wrong here?

#!/bin/sh

####################################################################################################
#
# DEFINE VARIABLES & READ IN PARAMETERS
#
####################################################################################################
#
# A HARDCODED VALUE FOR "processNameX," "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. 
# processNameX=Safari.app 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.
#
# Created by Sepie Moinipanah, November 2016
#
####################################################################################################

processName1=""
processName2=""
processName3=""
processName4=""
processName5=""
jamfPolicyType=""
eventorIDName=""

####################################################################################################
#
# SCRIPT CONTENTS - DO NOT MODIFY BELOW THIS LINE
#
####################################################################################################

# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 4 AND, IF SO, ASSIGN TO "processName1"

if [[ "$4" != "" ]] && [[ "$processName1" == "" ]]
then
    processName1=$4
fi

# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 5 AND, IF SO, ASSIGN TO "processName2"

if [[ "$5" != "" ]] && [[ "$processName2" == "" ]]
then
    processName2=$5
fi

# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 6 AND, IF SO, ASSIGN TO "processName3"

if [[ "$6" != "" ]] && [[ "$processName3" == "" ]]
then
    processName3=$6
fi

# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 7 AND, IF SO, ASSIGN TO "processName4"

if [[ "$7" != "" ]] && [[ "$processName4" == "" ]]
then
    processName4=$7
fi

# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 8 AND, IF SO, ASSIGN TO "processName5"

if [[ "$8" != "" ]] && [[ "$processName5" == "" ]]
then
    processName5=$8
fi

# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 9 AND, IF SO, ASSIGN TO "jamfPolicyType"

if [[ "$9" != "" ]] && [[ "$jamfPolicyType" == "" ]]
then
    jamfPolicyType=$9
fi

# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 10 AND, IF SO, ASSIGN TO "eventorIDName"

if [[ "$10" != "" ]] && [[ "$eventorIDName" == "" ]]
then
    eventorIDName=$10
fi

####################################################################################################
#
# JAMF HELPER CONTENTS - DO NOT MODIFY BELOW THIS LINE
#
####################################################################################################

/usr/bin/curl -s -o /tmp/settings_icon.png 
http://orig12.deviantart.net/8a27/f/2014/340/8/c/round_ios_7_settings_icon_by_pgbiel-d88y06v.png

icon="/tmp/settings_icon.png"
jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
windowType="hud"
description="One or more of the following applications are open. Please ensure that ALL are closed.

$processName1, $processName2, $processName3, $processName4, $processName5

Once confirmed, please try again."
button1="OK"
title="Warning: Application(s) Running"
alignDescription="left" 
defaultButton="1"
cancelButton="1"
timeout="30"

####################################################################################################
#
# CHECK TO SEE IF THE SPECIFIED PROCESS IS RUNNING, THEN ECHO STATEMENT DEPENDING ON CONDITION
#
####################################################################################################

processRunning1=$(ps axc | grep "${processName1}$")
processRunning2=$(ps axc | grep "${processName2}$")
processRunning3=$(ps axc | grep "${processName3}$")
processRunning4=$(ps axc | grep "${processName4}$")
processRunning5=$(ps axc | grep "${processName5}$")
jamf="/usr/local/bin/jamf"

if [[ $processRunning1 != "" ]] || [[ $processRunning2 != "" ]] || [[ $processRunning3 != "" ]] || [[ $processRunning4 != "" ]] || [[ $processRunning5 != "" ]]
then
     echo "$processName1, $processName2, $processName3, $processName4 or $processName5 is/are running. Prompt user to close the application(s) and re-run policy from Self Service."
     #JAMF Helper
     userChoice=$("$jamfHelper" 
-windowType "$windowType" 
-lockHUD 
-title "$title" 
-timeout "$timeout" 
-defaultButton "$defaultButton" 
-cancelButton "$cancelButton" 
-icon "$icon" 
-description "$description" 
-alignDescription "$alignDescription" 
-button1 "$button1")
else
     echo "$processName1, $processName2, $processName3, $processName4 or $processName5 is/are NOT running. Search for $jamfPolicyType triggered by $eventorIDName and install $processName1, $processName2, $processName3, $processName4 and $processName5."
     $jamf policy $jamfPolicyType $eventorIDName
fi

Best answer by chriscollins

@sepiemoini any positional parameters higher than 9 in bash need to use a more strict variable expansion. For parameters 10 and 11, where you are using "$10", "$11", change then to "${10}" and "${11}"

View original
Did this topic help you find an answer to your question?

2 replies

Forum|alt.badge.img+16
  • Honored Contributor
  • 403 replies
  • Answer
  • November 19, 2016

@sepiemoini any positional parameters higher than 9 in bash need to use a more strict variable expansion. For parameters 10 and 11, where you are using "$10", "$11", change then to "${10}" and "${11}"


sepiemoini
Forum|alt.badge.img+19
  • Author
  • Employee
  • 180 replies
  • November 20, 2016

Excellent, thanks @chriscollins--that did the trick!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings