How to Fetch Application Inventory from Clint Machine

sidharth_bhalla
New Contributor II

Anyone knows about how can fetch all Application data from client machine through policy or any other option.
I have already script for this but it's so complicated for me......
if i user terminal for run script the it's works... Also when run script silently push to client machine after that we must have to run command (sudo jamf policy ) to run script the it's working. if I wait for run successfully the become failed. Kindly help.............

!/bin/sh

Inventory script for hostname,ip address, cpu info, software installed

touch Desktop/hostname -f-swinv.txt
echo SWO-Linux >>Desktop/hostname -f-swinv.txt
echo =========DATE=========== >>Desktop/hostname -f-swinv.txt
/bin/date >>Desktop/hostname -f-swinv.txt
echo =========HOSTNAME=========== >>Desktop/hostname -f-swinv.txt
hostname -f >> Desktop/hostname -f-swinv.txt
echo >> Desktop/hostname -f-swinv.txt
echo =========IP ADDRESSES=========== >>Desktop/hostname -f-swinv.txt
ifconfig -a >>Desktop/hostname -f-swinv.txt
echo >> Desktop/hostname -f-swinv.txt
echo ===========HW/CPU INFO============== >>Desktop/hostname -f-swinv.txt
sysctl machdep.cpu >> Desktop/hostname -f-swinv.txt
echo >> Desktop/hostname -f-swinv.txt
echo ==============SW INSTALLED Sys Profiler================ >>Desktop/hostname -f-swinv.txt
system_profiler SPApplicationsDataType >> Desktop/hostname -f-swinv.txt
echo >> Desktop/hostname -f-swinv.txt

4 REPLIES 4

talkingmoose
Moderator
Moderator

Most of this information is already collected by Jamf Pro with each inventory update. You can search your Jamf Pro server for the computer name and you will find it under the Inventory tab.

What is your goal for running a script that writes this information to a file on the user's desktop? Maybe, if we understood what you need, we could help you find a better solution.

sidharth_bhalla
New Contributor II

Hi,

Thanks so much for your guidance, that's help.

We want All applications details belongs to one Selected MAC Machines. Above script is fulfilling our requirement and working fine manually.

While we are trying to enable the same script through JAMF policy, it's getting failed. Same script is working fine manually using terminal.

Please advise if we can pullout only Applications details, individual for one MAC from JAMF pro.

ryan_ball
Valued Contributor

Nobody wants to tell you but that script is a horrible way to do this. What that script does is take the information you are wanting and just export it to a file somewhere on the client machine. Why you'd want to do that is beyond me, let me offer an alternative that was already mentioned.

If you want to populate the Jamf Pro Server with similar details as your script you can simply do this:

#!/bin/bash
/usr/local/bin/jamf recon

If you want to scour other Mac directories for applications in your JSS you can go to Settings > Computer Management > Inventory Collection > Software - then add in the directories you want to search for applications.

However, if the goal is to write the information to a file on the client, here is a version of your script that might work. It will create the file in the /private/tmp directory.

#!/bin/bash
# Inventory script for hostname,ip address, cpu info, software installed
directory="/private/tmp"
macName=$(hostname -f)
file="$directory/$macName-swinv.txt"
touch "$file"
echo SWO-Linux >> "$file"
echo =========DATE=========== >> "$file"
/bin/date >> "$file"
echo =========HOSTNAME=========== >> "$file"
/bin/hostname -f >> "$file"
echo >> "$file"
echo =========IP ADDRESSES=========== >> "$file"
/sbin/ifconfig -a >> "$file"
echo >> "$file"
echo ===========HW/CPU INFO============== >> "$file"
/usr/sbin/sysctl machdep.cpu >> "$file"
echo >> "$file"
echo ==============SW INSTALLED Sys Profiler================ >> "$file"
/usr/sbin/system_profiler SPApplicationsDataType >> "$file"
echo >> "$file"

exit 0

mm2270
Legendary Contributor III

You might want to explore the API, which would let you pull out a single computer's captured application list (and version numbers) in XML or JSON format.

Example:

curl -sku apiuser:apipass -H "Accept: application/xml" https://jamfpro.url.com/JSSResource/computers/serialnumber/<serial_number>/subset/software | xpath '/computer/software/applications' | xmllint --format -

Or drop the xpath if you also want package receipts, plug-ins and other items within the 'software' section:

curl -sku apiuser:apipass -H "Accept: application/xml" https://jamfpro.url.com/JSSResource/computers/serialnumber/<serial_number>/subset/software | xmllint --format -