Skip to main content
Question

Modify Script or Policy Script Parameters via API or other method ?


Forum|alt.badge.img+12
  • Valued Contributor
  • 190 replies

Hi,

i'm seeing if there's a way that i can have one Mac create a list of ok'd Apple updates then have that list end up on all of our Macs, in the form of a text file or something that can be read from,

would it be possible to modify elements of an existing script on the JSS or populate $4 to $11 script parameters within a policy from a standalone Mac, has anyone had experience with anything similar ?

2 replies

Forum|alt.badge.img+7
  • Contributor
  • 38 replies
  • November 13, 2017

Hi there,

If you run this script on a machine (to through a Casper/Jamf Pro policy) you can modify a particular string a script's contents if you know the script ID, you could modify the parameter numbers to allow it to work from the JSS or run it as is:

#!/bin/bash


#sets parameters for JSS User, password and URL
jssuser=$1
jsspass=$2
jssurl=$3

#takes the JSS Script ID number for the script you wish to modify
scriptid=$4

#takes the text you with to replace
replaceThis=$5

#Has text you wish to replace the above var's text with
withThis=$6

#creates temporary file
touch /tmp/scriptfile1

#Puts script contents into a temporary file
curl -sS -u $jssuser:$jsspass $jssurl/JSSResource/scripts/id/$scriptid | xpath //script//script_contents | sed 's/<script_contents>//g' | sed 's/</script_contents>//g' > /tmp/scriptfile1

#Carries out replacement operation
sed -i -e "s/$replaceThis/$withThis/g" /tmp/scriptfile1

#Loads new script into variable
scriptData=$(cat /tmp/scriptfile1)

#pushes new script contents to JSS
curl -X PUT -H "Accept: application/xml" -H "Content-type: application/xml" -k -u 'jssuser:jsspass' -d "<script><script_contents>$scriptData</script_contents></script>" $jssurl/JSSResource/scripts/id/$scriptid

#removes temporary file
rm /tmp/scriptfile1

exit 0

Hope that helps!

Christian


Forum|alt.badge.img+12
  • Author
  • Valued Contributor
  • 190 replies
  • November 21, 2017

Thanks for your help Christian !,

this looks like it can do what i need, once i get a chance to tinker with it i'll post the outcome,
cheers,
Andy


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