Posted on 08-24-2024 03:01 AM
Hi
I am trying to upload iPad details using the API, this script did work it now wont it comes up with an error, would anyone be able to point me to what the issue is
bellow is the error
-:10: parser error : Opening and ending tag mismatch: br line 8 and p
</p>
^
-:11: parser error : Opening and ending tag mismatch: p line 8 and body
</body>
^
-:12: parser error : Opening and ending tag mismatch: body line 5 and html
</html>
^
-:12: parser error : Premature end of data in tag html line 1
</html>
And bellow here is the script
#!/bin/bash
############################################################
#SCRIPT INFO
############################################################
CURRENTPATH=$( cd "$( dirname "$0" )" && pwd )
CURRENTNAME=$(basename "$0")
CURRENTSCRIPT="$CURRENTPATH/$CURRENTNAME"
############################################################
# JSS Variables
############################################################
APIUSER="APIUSER"
APIPASS="Password12345"
JSSURL="https://????.jamfcloud.com"
############################################################
# Script Variables
############################################################
THISDATE=$(date "+%Y-%m-%d-%H%M%S")
INPUTFILE="$CURRENTPATH/MBUS1.csv"
LOGPATH="$CURRENTPATH/JSS_Import_Report_$THISDATE.xls"
echo "$CURRENTSCRIPT Using Values from the spreadsheet: $INPUTFILE"
echo "Exporting Log to $LOGPATH"
#########################################################
# Create Header
#########################################################
echo "ID\tSerial Number\tAsset\tUsername\tSITEID\tSNAME\tFull Name\tPosition" >> "$LOGPATH" 2>&1
#########################################################
# Get list of Serial Numbers -
# FIRST LINE OF INPUT FILE MUST HAVE A HEADER
# Not because it matters, but because we are skipping it when
# we read in the Serial Numbers.
#########################################################
declare -a SERIAL_ARRAY
SERIAL_ARRAY=$(awk -F, 'NR>1 {print $1}' "$INPUTFILE")
#########################################################
# For Loop with Serial Number
#########################################################
for i in ${SERIAL_ARRAY[@]};do
#########################################################
# Find the JSS ID of the device by it's Serial Number
# About everything in the API uses the JSS ID.
# This is old, we can now use Serial Number, but this is a good example
# of finding data.
#########################################################
# Curl defaults to a GET, we do not need to specify it.
#########################################################
JSSID=$(curl -s -k -H "Accept: application/xml" -u "$APIUSER":"$APIPASS" "$JSSURL"/JSSResource/mobiledevices/serialnumber/"$i" | xmllint --format - | awk -F '[<>]' '/id/{print $3;exit}')
#########################################################
# Get Values from Spreadsheet
# If adding to this list, be sure to increment the "print"
# value in awk.
#########################################################
ASSET_TAG=$(awk -F, "/$i/{print \$2}" "$INPUTFILE")
USERNAME=$(awk -F, "/$i/{print \$3}" "$INPUTFILE")
SITEID=$(awk -F, "/$i/{print \$4}" "$INPUTFILE")
SNAME=$(awk -F, "/$i/{print \$5}" "$INPUTFILE")
FNAME=$(awk -F, "/$i/{print \$6}" "$INPUTFILE")
PNAME=$(awk -F, "/$i/{print \$7}" "$INPUTFILE")
#########################################################m
# Do Mobile Devices
#########################################################
#########################################################
# Set Asset Tag
#########################################################
curl -s -k -H "Content-type: application/xml" -X PUT -d "<mobile_device><general><asset_tag>$ASSET_TAG</asset_tag></general></mobile_device>" -u "$APIUSER":"$APIPASS" "$JSSURL"/JSSResource/mobiledevices/id/"$JSSID" >/dev/null
#########################################################
# Set Username
#########################################################
curl -s -k -H "Content-type: application/xml" -X PUT -d "<mobile_device><location><username>$USERNAME</username></location></mobile_device>" -u "$APIUSER":"$APIPASS" "$JSSURL"/JSSResource/mobiledevices/id/"$JSSID" >/dev/null
#########################################################
# Set Site
#########################################################
curl -s -k -H "Content-type: application/xml" -X PUT -d "<mobile_device><general><site><id>$SITEID</id><name>$SNAME</name></site></general></mobile_device>" -u "$APIUSER":"$APIPASS" "$JSSURL"/JSSResource/mobiledevices/id/"$JSSID" >/dev/null
#########################################################
# Set Device Name
#########################################################
curl -s -k -H "Content-type: application/xml" -u "$APIUSER":"$APIPASS" "$JSSURL"/JSSResource/mobiledevicecommands/command/DeviceName/"$USERNAME"/id/"$JSSID" -X POST >/dev/null
#########################################################
# Update Inventory
# If using LDAP lookups, User and Location data will
# be updated at this time.
#########################################################
curl -s -k -H "Content-type: application/xml" -X PUT -d "<mobile_device><command>UpdateInventory</command></mobile_device>" -u "$APIUSER":"$APIPASS" "$JSSURL"/JSSResource/mobiledevices/id/"$JSSID" >/dev/null
#########################################################
# Waits while device checks in
#########################################################
echo Waiting on Device
sleep 18
#########################################################
# Gets Full Name of user after upodate
#########################################################
FNAME=$(curl -s -k -H "Accept: application/xml" -u "$APIUSER":"$APIPASS" "$JSSURL"/JSSResource/mobiledevices/id/$JSSID/subset/Location | xmllint --format - 2>/dev/null | awk -F'>|<' '/<real_name>/{print $3}') >/dev/null
#########################################################
PNAME=$(curl -s -k -H "Accept: application/xml" -u "$APIUSER":"$APIPASS" "$JSSURL"/JSSResource/mobiledevices/id/$JSSID/subset/Location | xmllint --format - 2>/dev/null | awk -F'>|<' '/<position>/{print $3}') >/dev/null
#########################################################
echo "$JSSID\t$i\t$ASSET_TAG\t$USERNAME\t$SITEID\t$SNAME\t$FNAME\t$PNAME" >> "$LOGPATH" 2>&1
#########################################################
done
open $LOGPATH
I cant seem to work out the issue
thank you in advance
Solved! Go to Solution.
Posted on 08-24-2024 04:58 AM
I suspect your CSV file isn’t correct. A simple thing you can do is add some logging to your script. It doesn’t need to be complicated — just include some echo commands that echo each of your variables after you set them. You’ll see them as you’re running your script. While troubleshooting, you may also want to add an “exit” command just before your curl uploads to stop the script before it tries to upload.
Another thing you can do is add “set -x” on the second line. This will turn on some very verbose feedback that may help you troubleshoot.
Posted on 08-24-2024 04:58 AM
I suspect your CSV file isn’t correct. A simple thing you can do is add some logging to your script. It doesn’t need to be complicated — just include some echo commands that echo each of your variables after you set them. You’ll see them as you’re running your script. While troubleshooting, you may also want to add an “exit” command just before your curl uploads to stop the script before it tries to upload.
Another thing you can do is add “set -x” on the second line. This will turn on some very verbose feedback that may help you troubleshoot.
Posted on 08-24-2024 07:39 AM
Great thanks, i will try that, this used to work not really sure why its not now i will look at the csv
Posted on 08-25-2024 05:29 AM
Hi
Does anyone know the CSV format that i should use and do all the columns need to be populated,
i have saved the csv as a UTF-8 COMMA DELIMITED is that correct
Thanks in advance
Posted on 08-27-2024 04:45 AM
Thanks for your help i started the csv fresh and it worked all ok