If this is being run against a Mac running macOS Big Sur, you may want to take a look at this article, which explains how xpath now works in that OS.
https://scriptingosx.com/2020/10/dealing-with-xpath-changes-in-big-sur/
Thank you @mm2270. I wasn't aware of that, although I can confirm that also previous version of xpath work on Big Sur.
At the end I figured out how to have the list of apps and their scope. The result is not perfect but works for me, and I'm learning a lot from this.
Here is the code that I made finally:
#!/bin/bash
# 1) Author: Lorenzo Fittarelli
# 2) Created: 16/12/2021
# 3) Modified: 16/12/2021
# 4) Description: Outputs the list of Mobile device Applications and their scope
# 5) Usage: ./mobDevAppsScope.sh
user=<yourUserName>
pass=<yourPassword>
while read column1; do
# Each of the variables below has a command that extracts the scope for the apps. The scope includes multiple tags, therefore I had to create a command for each of them.
appScope1=$(curl -sku $user:$pass -X GET -H "Accept: application/xml" "https://<yourJamfInstance>/JSSResource/mobiledeviceapplications/name/$column1" | xmllint --xpath "/mobile_device_application/scope/all_mobile_devices/text()" - | awk 'BEGIN { OFS = ";"; ORS = "\\n\\n" }{ print $0 }')
appScope2=$(curl -sku $user:$pass -X GET -H "Accept: application/xml" "https://<yourJamfInstance>/JSSResource/mobiledeviceapplications/name/$column1" | xmllint --xpath "/mobile_device_application/scope/all_jss_users/text()" - | awk 'BEGIN { OFS = ";"; ORS = "\\n\\n" }{ print $0 }')
appScope3=$(curl -sku $user:$pass -X GET -H "Accept: application/xml" "https://<yourJamfInstance>/JSSResource/mobiledeviceapplications/name/$column1" | xmllint --xpath "/mobile_device_application/scope/mobile_devices/mobile_device/name/text()" - | awk 'BEGIN { OFS = ";"; ORS = "\\n\\n" }{ print $0 }')
appScope4=$(curl -sku $user:$pass -X GET -H "Accept: application/xml" "https://<yourJamfInstance>/JSSResource/mobiledeviceapplications/name/$column1" | xmllint --xpath "/mobile_device_application/scope/buildings/building/name/text()" - | awk 'BEGIN { OFS = ";"; ORS = "\\n\\n" }{ print $0 }')
appScope5=$(curl -sku $user:$pass -X GET -H "Accept: application/xml" "https://<yourJamfInstance>/JSSResource/mobiledeviceapplications/name/$column1" | xmllint --xpath "/mobile_device_application/scope/departments/department/name/text()" - | awk 'BEGIN { OFS = ";"; ORS = "\\n\\n" }{ print $0 }')
appScope6=$(curl -sku $user:$pass -X GET -H "Accept: application/xml" "https://<yourJamfInstance>/JSSResource/mobiledeviceapplications/name/$column1" | xmllint --xpath "/mobile_device_application/scope/mobile_device_groups/mobile_device_group/name/text()" - | awk 'BEGIN { OFS = ";"; ORS = "\\n\\n" }{ print $0 }')
# Output to a CSV file the name of the Mobile Device App (column1 variable) and the scopes. Each scope is divided here by a column so that in the CSV file it appears in different columns.
echo "$column1" , "$appScope1" , "$appScope2" , "$appScope3" , "$appScope4" , "$appScope5" , "$appScope6"
# The while loop takes as input the CSV file that provides the Mobile Device App Names and redirects the output to a new CSV file.
# any error is output into an error log txt file
done < <pathToInputCSV> > <pathToOutputCSV> 2>> <pathToErrorLog>
I hope it helps anyone who's looking for the same result. And of course, I'm happy to receive constructive critics to my code 🙂