Hi Everyone,
I'm new to bash scripting and the JAMF API and need some help. I'm trying to export a csv file with the Serial Number (Column A) and Computer Name (Column B) so I can then import it nightly into our inventory system. I use the computer name to assign each computer and iOS device to that user so this will help confirm who has the device in the inventory.
I have figured out how to export the file, but it all seems to be in 1 cell. I'm looking for help on what I should do to break it apart. Thank you in advance.
!/bin/bash
server information
jamfUser="apiread"
jamfPass="apireadpassword"
jamfURL="https://jss.url:8443/JSSResource"
search computers and GET SerialNumbers and ComputerNames exported to csv file
apiData=$(/usr/bin/curl
--user "$jamfUser":"$jamfPass"
--header "Accept: text/xml"
--request GET
$jamfURL/computergroups/id/1 |
/usr/bin/xpath "/computer_group/computers" |
/usr/bin/xmllint --format - |
/usr/bin/grep -E "<serial_number>|<name>" |
/usr/bin/awk -F "<serial_number>|</serial_number>|<name>|</name>" '{ print $4,$2 }'
)
echo $apiData --output
echo $apiData > ~/Desktop/computersList.csv