@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.
That is awesome. Thanks so much.
@ryan.ball
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
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)
@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
@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.
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!