@Sandy
I just whipped up a quick script to let me get a birds-eye-view of app counts on shared carts the other day. You'll probably need to tweak what separates the base name from the device's number—and possibly the number of digits generated for the sequence since configurator doesn't do 01, 02, 03... for single digits.
#!/bin/bash
apiPath="https://yourjss/JSSResource/mobiledevices/name/"
apiReadOnlyUser=user
apiReadOnlyPass=pass
echo ""
echo "Please enter the basename for the iPads you'd like to look up"
read baseName
echo ""
echo "How many iPads are in the cart?"
echo "(Never hurts to over-estimate)"
read END
echo ""
echo "Let me look those up for you..."
for i in $(seq -w 01 $END)
do
appcount=`curl -s -u $apiReadOnlyUser:'$apiReadOnlyPass' $apiPath$baseName-$i/subset/applications | /usr/bin/awk -F'<size>|</size>' '{print $2}'`
if [ "$appcount" == "" ]
then
echo "$baseName-$i: I don't think this iPad exists."
else
echo "$baseName-$i: $appcount apps"
fi
done
Hopefully I didn't break something making it generic...
@jbourdon This is cool, and so close!
How would I get the hyphen out of the name search?
Our naming uses a space before the seat but does have leading zeroes so feedback comes back:
MR Cart 4-01: I don't think this iPad exists.
Actual name is MR Cart 4 01
I tried a few things but really am just guessing :)
@jbourdon, I found the correct places to remove the hyphen and now the feedback matches the device name but still says not found:
moCart 4 30: I don't think this iPad exists
Actual Device name: moCart 4 30
I also swapped in my full api admin user/password to be sure it was not a permissions thing.
no help
Spaces...
Try replacing the bottom part with this
for i in $(seq -w 01 $END)
do
deviceName="$baseName $i"
curlDeviceName=${DeviceName// /%20}
appcount=`curl -s -u $apiReadOnlyUser:'$apiReadOnlyPass' $apiPath$curlDeviceName/subset/applications | /usr/bin/awk -F'<size>|</size>' '{print $2}'`
if [ "$appcount" == "" ]
then
echo "$baseName $i: I don't think this iPad exists."
else
echo "$baseName $i: $appcount apps"
fi
done
I tried not to guess at the changes you made to fit your environment, so you might want to give it a once over.
shoot, no, the feedback that returns has the names exactly correct as they are in my jss, but says they don't exist.
both with my edits and the one you just sent.
My bad. Measure twice, post once.
I had "deviceName" and "DeviceName" which are not the same thing. Make sure that the "deviceName" on the line that sets "curlDeviceName" has a lower case d.
dang. I tried every combo of DeviceName, deviceName, all same result: "I don't think this iPad exists."
I had a moment to try a few things out with iPads with spaces in their names in my environment. Hopefully this will get you closer:
#!/bin/bash
apiPath="https://yourjssurl/JSSResource/mobiledevices/name/"
apiReadOnlyUser=user
apiReadOnlyPass='pass'
echo ""
echo "Please enter the basename for the iPads you'd like to look up"
echo "(Make sure to include any separators between your basename and the device's number. If a space separates your basename from the device number use '%20' instead at the end of your basename.)"
read baseName
echo ""
echo "How many iPads are in the cart?"
echo "(Script assumes number sequences like 01, 02, 03... Enter at least '10' for double digits to work correctly)"
read END
echo ""
echo "Let me look those up for you..."
for i in $(seq -w 01 $END)
do
individualDeviceName="$baseName$i"
curlDeviceName=${individualDeviceName// /%20}
appcount=`curl -k -s -u $apiReadOnlyUser:"$apiReadOnlyPass" $apiPath$curlDeviceName/subset/applications | /usr/bin/awk -F'<size>|</size>' '{print $2}'`
if [ "$appcount" == "" ]
then
echo "$baseName: I don't think this iPad exists, man."
else
echo "$baseName: $appcount apps"
fi
done
Other than that... Apparently, if you're on Java OpenJDK 6 your JSS will return JSON instead of XML, and we want XML. https://jamfnation.jamfsoftware.com/discussion.html?id=7673
@jbourdon!
I want to thank you and update you on my progress!
I have the script working, weirdly but working :)
Despite every single way I can think of to modify, the results come back looking like this:
moCart 4%20: 73 apps
moCart 4%20: 73 apps
moCart 4%20: 72 apps
moCart 4%20: 73 apps
moCart 4%20: 72 apps
moCart 4%20: 73 apps
etc.
But they come back in order and it is what my tech wanted so thanks much!!
He just pastes into excel.
The stupidest thing is that of the 30 devices, 4 are short 1 app, and it is a different app on each device....
Apple Configurator 1.7.2. grrrr. no errors when syncing, just randomly skipped 1 app on 4 devices
Sandy
@jbourdon!
Thank you for posting this script. I am trying to run it against my JSS (9.99.0) and it is coming back that it cannot find the device every time. After inspecting all the calls, if I run
curl -k -s -u user:pass https://jssurl/JSSResource/mobiledevices/name/DEVICENAME/subset/applications
in Terminal, it returns everything but the line with <size>#</size>.
If I paste that URL directly into a browser, it has the line with size in it. I am not familiar with the APIs at all, so I'm at a complete loss. Any idea why it might be omitting that tag? Without it, I can't see the app count.
Thanks.
@austin_henderson Try adding -H "Accept: text/xml"
to the curl command in your script. The JSS API now returns JSON responses by default, and that isn't going to make the awk
part of your script happy
@austin_henderson Try this version and see if you're any better off.
Awesome!!!
Thanks so much for your help jbourdon!!! The script now returns correct results.
Any way to modify this script to accept a CSV of serial numbers instead of device names? My carts don't always have sequential numbers because of failed devices being pulled out, etc.
This a basic workflow for parsing out and looping through a CSV with Unix line breaks.
echo "Please drag and drop your CSV into this window and press enter."
read csvfile
INPUT="$csvfile"
OLDIFS=$IFS
IFS=","
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read username fullname email serialnumber
do
curl -s -u https://yourjssurl/JSSResource/whatever/you/need/to/do/$serialnumber
index=$[$index+1]
done < $csvfile