This is for iOS devices. I have a script that I use to update user’s extension attributes based on the classes they are in. Well after the semester ends, I wanted to clear out this information as I have classes setup based on these extension attributes and and the use of smart user groups. When trying to use a bash script to read a csv file and delete all of those attributes, the script itself says that it was successful but it does not update the user. I’ve looked at both the JSS and the API and the info is not updated. It used to work and I was hoping with the new 9.99.2 update that it would be fixed but alas nothing. Please let me know if I’m missing something.
I know the script can read the cvs file because I get the correct username from each row. My jss user is an administrator and has full access. I can update mobile device xml's with no problem.
Here is my script:
#!/bin/sh
#Variables
jssAPIUsername="<jssusername>"
jssAPIPassword="<jsspassword>"
jssAddress="https://company.jamfcloud.com/"
#Finding which CSV to use
read -p "S, F, W or Input? (S, F, W, input)" location
shopt -s nocasematch
case "$location" in
s)
file="./S_Student_Update.csv"
;;
f)
file="./F_Student_Update.csv"
;;
w)
file="./W_Student_Update.csv"
;;
input)
read -p "Please input the location of your csv file: " file
;;
*)
echo "Invalid Location. Please try again."
exit 1
;;
esac
#Option to read in the path from Terminal
if [[ "$file" == "" ]]; then
echo "There was not a vaild path to the CSV."
echo "Please enter a path to the CSV"
read file
fi
#Verify we can read the file
data=`cat $file`
if [[ "$data" == "" ]]; then
echo "Unable to read the file path specified."
echo "Ensure there are no spaces and that the path is correct."
echo "Please try again."
exit 1
fi
#Find how many users to import
userqty=`awk -F, 'END {printf "%s
", NR}' $file`
#Set a counter for the loop (Start at 1 because of the head in the CSV)
counter="1"
#Clears the logfile or creates it
echo "" > "./jss_logfile-delete.txt"
#Loop through the CSV and submit data to the API
while [ $counter -lt $userqty ]
do
counter=$[$counter+1]
line=`echo "$data" | head -n $counter | tail -n 1`
username=`echo "$line" | awk -F , '{print $1}'`
delete=""
echo "Attempting to update: $username"
echo -n "."
# Prepare XML for update
apiData="<user><extension_attributes><extension_attribute><name>Class ID #1</name><value>${delete}</value></extension_attribute><extension_attribute><name>Class ID #2</name><value>${delete}</value></extension_attribute><extension_attribute><name>Class ID #3</name><value>${delete}</value></extension_attribute><extension_attribute><name>Class ID #4</name><value>${delete}</value></extension_attribute><extension_attribute><name>Class ID #5</name><value>${delete}</value></extension_attribute></extension_attributes></user>"
echo -n "."
#Run the User update
Uoutput=`curl -sSkiu "${jssAPIUsername}":"${jssAPIPassword}" -H "Content-Type: text/xml" -d "<?xml version="1.0" encoding="ISO-8859-1"?>$apiData" -X PUT ${jssAddress}/JSSResource/users/name/${username}`
echo -n "."
echo "******************************" >> "./jss_logfile-delete.txt"
echo "Update Log for $username" >> "./jss_logfile-delete.txt"
echo "******************************" >> "./jss_logfile-delete.txt"
echo "" >> "./jss_logfile-delete.txt"
echo $Uoutput >> "./jss_logfile-delete.txt"
echo "" >> "./jss_logfile-delete.txt"
#Check if password needs to be updated in script
Login=""
Login=`echo $Uoutput | grep "HTTP/1.1 401 Unauthorized"`
if [ "$Login" != "" ]; then
echo " ERROR"
echo ""
echo "***AUTHORIZATION ISSUE!***"
echo ""
echo "***Please update your password!***"
echo ""
exit 1
fi
#Error Checking
Uerror=""
Uerror=`echo $Uoutput | grep "HTTP/1.1 404 Not Found"`
if [[ "$Uerror" != "" ]]; then
echo " ERROR..."
sleep .5
echo "$username Not Found."
echo ""
else
echo " OK"
sleep .5
echo "$username Updated Successfully."
echo ""
fi
done < $file
exit 0