Posted on 09-25-2018 11:30 AM
This would be ideal for our helpdesk/field technicians to launch the script from self service so when they are either remotely logged in or at the machine physically they can verify that the machine is in the correct site and check other things in the id page. I'm new to scripting so passing parameters ect is not my specialty.
Something like this where jamf.com is our jss
/usr/local/jamf/bin/jamf recon | grep '<computer_id>' > '/private/var/jss_computer_id.xml'
open -a /Applications/Safari.app https://Jamf.com:8443/computers.html?id='<computer_id>'&o=r
I know this doesn't pass the computer_id, but it does put the id locally in the xml file
Solved! Go to Solution.
Posted on 09-25-2018 12:56 PM
@dan.gregson Here ya go. No need to hard code the JSS URL in there:
#!/bin/bash
jssURL=$(defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url | sed s'/.$//')
id=$(jamf recon | grep '<computer_id>' | xmllint --xpath xmllint --xpath '/computer_id/text()' -)
open -a "Safari" "$jssURL/computers.html?id=$id&o=r"
exit 0
As always with jamf commands you should run with sudo when testing.
Posted on 09-25-2018 12:56 PM
@dan.gregson Here ya go. No need to hard code the JSS URL in there:
#!/bin/bash
jssURL=$(defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url | sed s'/.$//')
id=$(jamf recon | grep '<computer_id>' | xmllint --xpath xmllint --xpath '/computer_id/text()' -)
open -a "Safari" "$jssURL/computers.html?id=$id&o=r"
exit 0
As always with jamf commands you should run with sudo when testing.
Posted on 08-03-2021 08:12 AM
Your handy script helped me simplify a gathering logs script I found. The script was mostly correct but the conversion and curl command was a little overdone. Your script helped me keep it simple. So thank you!
Posted on 09-25-2018 01:04 PM
That is awesome. Thanks so much.
Posted on 09-26-2018 12:56 AM
now thats clean script!!!! this is what i came up with for dans other post....then I came here.... lol...I REALLY GOTTA THINK BASH!
#!/usr/bin/osascript
try
set UNAME to "root"
set PASSW to "password"
set jsslinksuffix to "&o=r"
set rawGREPid to do shell script "sudo /usr/local/bin/jamf recon | grep '<computer_id>'" user name UNAME password PASSW with administrator privileges
set FourCharacterID to text 14 thru 17 of rawGREPid
if FourCharacterID contains "<" then set ThreeCharacterID to text 14 thru 16 of rawGREPid
if FourCharacterID contains "<" then
do shell script "open -a /Applications/Safari.app https://jss.jamf.com:8443/computers.html?id=" & quoted form of (ThreeCharacterID & jsslinksuffix)
else
do shell script "open -a /Applications/Safari.app https://jss.jamf.com:8443/computers.html?id=" & quoted form of (FourCharacterID & jsslinksuffix)
end if
end try
Posted on 11-12-2018 09:38 AM
Great script @ryan.ball, but you have to wait for Recon to finish running and that can take a couple of minutes. It's almost faster to get the S#, open the jss, and search based on the S#.
I guess you could have a policy run a script to grep the computer_id (shouldn't have to do it more than once, but maybe have the script run monthly) and save it in a file somewhere that you can read from a self service policy later (if it's not there, then it can do the long method). I might look into that a shot... (eat my own dog food)
Posted on 11-13-2018 06:23 AM
@cwaldrip Everybody wants instant satisfaction :)
This will do:
#!/bin/bash
# Pass in user credentials in parameters 4 and 5
apiUser="$4"
apiPass="$5"
jssURL=$(defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url | sed s'/.$//')
serial=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
id=$(curl -sku "$apiUser:$apiPass" "$jssURL/JSSResource/computers/serialnumber/$serial" | xmllint --xpath xmllint --xpath '/computer/general/id/text()' - 2>/dev/null)
if [[ -z "$id" ]]; then
echo "Could not determine Mac's Jamf Pro ID; exiting."
exit 1
else
open -a "Safari" "$jssURL/computers.html?id=$id&o=r"
fi
exit 0