More Script Parameters

milesleacy
Valued Contributor

Hi Nation,

I had to deliver a script that required more than 8 custom parameters. The below is my somewhat tedious but functional solution to this dilemma.

Essentially, I am putting more than one value into each of the Jamf Pro script parameters, and then parsing those multi-value variables within the script. The key points are knowing how to use awk and selecting a field separator character for your multi-value parameters that is neither in your expected data sets nor has special meaning to your scripting language.

Under the user variables heading below, I have populated the string "x?y?z" to illustrate the point. This is what would be populated via Jamf Pro script parameter 4 if the user variable declaration for $letters were left blank. As you can see, "x" is my first value, "y" the second, and "z" the third, using "?" as a field separator and then using awk to parse out the values.

This method requires close attention to detail, but allows use of many more script parameter values than Jamf Pro currently allows. It is my hope that Jamf will deliver on the feature request: More script parameters! so that we can discontinue this workaround.

Thanks!

#!/bin/bash

# Multiple data points per Jamf Pro script parameter

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# USER VARIABLES - These can be left blank here and populated by Jamf policy parameters
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

letters="x?y?z"

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Jamf policy parameters
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

[ "$4" != "" ] && [ "$letters" == "" ] && letters=$4

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Parsing Jamf policy parameters
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

theXValue=$(awk -F "?" '{print $1}' <<< "$letters")

theYValue=$(awk -F "?" '{print $2}' <<< "$letters")

theZValue=$(awk -F "?" '{print $3}' <<< "$letters")

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Main Script
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

printf "%s
" "The X value is $theXValue."

printf "%s
" "The Y value is $theYValue."

printf "%s
" "The Z value is $theZValue."
0 REPLIES 0