Posted on 07-10-2024 11:07 PM
Hello everyone.
As a Jamf admin for 9 months, I can't find a solution to my problem. I allow myself to present my problem / reflection.
I am in charge of setting up an iPad lock system outside of class hours. The plan that was chosen by our management is that from a certain time of day, the iPads in question will switch to Single App mode on the clock and unlock the iPad in the morning before resuming classes. On this part, I have no worries, I will set up a crontab with two intelligent groups.
My problem is rather in the shell to make the changes. I expose to you what I thought, and the code which unfortunately is not functional in order to have your help.
In order to be able to make the rotations, I created an extension attribute named Lock_Etudiant (ID2) with which I insert two values (Lock or Unlock). Regardless of the values, the iPad will travel between my two intelligent groups in order to set up this Single App or remove it.
Unfortunately, I can't change the values in this attribute. Here is the code that I have put in place to make the change
#!/bin/sh
apiuser="xxxxxxx"
apipass="xxxxxxx"
jamfProURL="https://xxxxxxx.jamfcloud.com"
authToken=$( /usr/bin/curl \
--request POST \
--silent \
--url "${jamfProURL}/api/v1/auth/token" \
--user "${apiuser}:${apipass}" )
echo "$authToken"
token=$( /usr/bin/plutil \
-extract token raw - <<< "$authToken" )
if [ -z "$token" ]; then
echo "Erreur: impossible d'obtenir le jeton d'authentification"
exit 1
fi
endpoint="JSSResource/mobiledevices/id/4"
data="<extension_attribute><id>2</id><value>Lock</value></extension_attribute>"
curl -s --header "Authorization: Bearer $token" -H "accept: text/xml" --data "$data" "${jamfProURL}/${endpoint}" -X PUT 1> /dev/null
if [[ "$?" == "0" ]]; then
echo " Commande traitée avec succès"
else
echo " Erreur lors du traitement de la commande"
fi
curl --request POST \
--url "${jamfProURL}/api/v1/auth/invalidate-token" \
--header "Authorization: Bearer ${token}"
I removed the values in data and put the variables in raw inside to see if it solves my problem, and unfortunately nothing happens.
Can someone guide me or point me to a solution.
Thanking you.
Posted on 07-11-2024 05:56 AM
after shebang add set -x
#!/bin/sh
set -x
then you can see the output of the script... and maybe see what its not working
also..this variable is not being populated?
${endpoint}
Posted on 07-11-2024 11:08 PM
I ended up finding a solution that works for my use. I am sharing my code that works for my use, I have integrated a loop to browse a smart group of iPads in order to make the change on all the iPads in this group.
deviceIDs=( $(curl -k -s --header "Authorization: Bearer $token" $jamfProURL/JSSResource/mobiledevicegroups/id/$mobileDeviceGroupID -H "Accept: application/xml" -X GET | xmllint --xpath "//mobile_device_group/mobile_devices" - | /usr/bin/perl -lne 'BEGIN{undef $/} while (/<id>(.*?)<\/id>/sg){print $1}' ) )
for i in ${deviceIDs[@]}; do
# Création du fichier XML pour l'attribut d'extension
echo Numéro du ipad "$i"
ea_name=$nom_attribut_extension
ea_value=$etat_etudiant
cat << EOF > /private/tmp/ea.xml
<mobile_device>
<extension_attributes>
<extension_attribute>
<name>$ea_name</name>
<value>$ea_value</value>
</extension_attribute>
</extension_attributes>
</mobile_device>
EOF
# Mise à jour de l'attribut d'extension avec une requête PUT et le fichier XML
curl -s --header "Authorization: Bearer $token" -H "Content-Type: application/xml" --data @/private/tmp/ea.xml "${jamfProURL}/JSSResource/mobiledevices/id/${i}/subset/extension_attributes" -X PUT
done