-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeviceApplicationSearch.sh
114 lines (102 loc) · 4.7 KB
/
DeviceApplicationSearch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
# Lookup mobile devices and computer via API and return a list of all the installed applications.
# This is designed to be run locally as a logged in user with the terminal (or other similar) application.
# This can create a preference file for future use for each Jamf Pro Server.
# A single Jamf Pro Server parameter is required and will exit with message if not provided.
#Copyright (C) 2018 Dan Engh
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
## Variables ##
deviceList=(
)
logFile="/path/to/file/application_list.txt"
# Do not change these
compPath="/computers/serialnumber/"
mobDevPath="/mobiledevices/serialnumber/"
currentUser=$( ls -l /dev/console | awk '{print $3}' )
# Get the JSS Server location along with credentials. If wanted, a plist can be created so that credentials can be stored and not re-entered every time.
JSSCredentials() {
if [[ -z $1 ]]; then
read -p "Enter a Jamf Pro host name. example: myjss.mycompany.com: " jssEntry
if [[ "$jssEntry" == "" ]]; then
echo "Jamf server not recognized. Please provide a Jamf URL host name. example: myjss.mycompany.com"
exit 1
else
jss="https://"$jssEntry":8443/JSSResource"
if [[ -e ~/Library/Preferences/com.my.company."$jssEntry".plist ]]; then
user=$( defaults read com.my.company."$jssEntry".plist api_user )
pw=$( defaults read com.my.company."$jssEntry".plist api_pass )
else
read -p "API Username: " user
read -p "API Password: " pw
read -p "Would you like to save these for later [y/n]? " createPlist
if [[ "$createPlist" == "y" ]]; then
defaults write com.my.company."$jssEntry".plist api_user "$user"
defaults write com.my.company."$jssEntry".plist api_pass "$pw"
echo "Preference file com.my.company."$jssEntry".plist created"
fi
fi
fi
else
jss="https://"$1":8443/JSSResource"
if [[ -e ~/Library/Preferences/com.my.company."$1".plist ]]; then
user=$( defaults read com.my.company."$1".plist api_user )
pw=$( defaults read com.my.company."$1".plist api_pass )
else
read -p "API Username: " user
read -p "API Password: " pw
read -p "Would you like to save these for later [y/n]? " createPlist
if [[ "$createPlist" == "y" ]]; then
defaults write com.my.company."$1".plist api_user "$user"
defaults write com.my.company."$1".plist api_pass "$pw"
echo "Preference file com.my.company."$1".plist created"
fi
fi
fi
}
# Look up the device and if it exists, return the list of installed applications
ApplicationCheck() {
for device in "${deviceList[@]}"; do
compExists=$( curl -k -u "$user":"$pw" -H"Accept: application/xml" "$jss""$compPath""$device" | xpath "/computer/general/name" | sed -e 's/<[^>]*>//g' )
mobDevExists=$( curl -k -u "$user":"$pw" -H"Accept: application/xml" "$jss""$mobDevPath""$device" | xpath "/mobile_device/general/name" | sed -e 's/<[^>]*>//g' )
if [[ "$compExists" != "" ]]; then
echo "computer exists"
appList=$( curl -k -u "$user":"$pw" -H"Accept: application/xml" "$jss""$compPath""$device" | xpath "/computer/software/applications/application/name" | sed -e 's/<[^>]*>/ /g' )
Logging
elif [[ "$mobDevExists" != "" ]]; then
appList=$( curl -k -u "$user":"$pw" -H"Accept: application/xml" "$jss""$mobDevPath""$device" | xpath "/mobile_device/applications/application/application_name" | LC_ALL=C sed -e 's/<[^>]*>/ /g' )
Logging
else
Logging
fi
done
}
# Logging function for writing out the list of apps to a log file as specified in the variable list
Logging() {
if [[ "$appList" != "" ]]; then
if [[ "$compExists" != "" ]]; then
echo ""$device" - "$compExists"" >> "$logFile"
echo "Application List" >> "$logFile"
echo "----------------" >> "$logFile"
echo "$appList" >> "$logFile"
else
echo ""$device" - "$mobDevExists"" >> "$logFile"
echo "Application List" >> "$logFile"
echo "----------------" >> "$logFile"
echo "$appList" >> "$logFile"
fi
else
echo ""$device" is not in Jamf" >> "$logFile"
fi
}
# Run the programs
JSSCredentials
ApplicationCheck