Skip to main content
Solved

Open a computer ID record in a browser via script

  • September 25, 2018
  • 6 replies
  • 0 views

Forum|alt.badge.img+3

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

!/bin/sh

/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

Best answer by ryan_ball

@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.

View original
Did this topic help you find an answer to your question?

6 replies

Forum|alt.badge.img+18
  • Contributor
  • 475 replies
  • Answer
  • September 25, 2018

@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.


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 7 replies
  • September 25, 2018

That is awesome. Thanks so much.


Hugonaut
Forum|alt.badge.img+15
  • Esteemed Contributor
  • 574 replies
  • September 26, 2018

@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

Forum|alt.badge.img+16
  • Valued Contributor
  • 401 replies
  • November 12, 2018

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)


Forum|alt.badge.img+18
  • Contributor
  • 475 replies
  • November 13, 2018

@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

dvasquez
Forum|alt.badge.img+16
  • Valued Contributor
  • 318 replies
  • August 3, 2021
ryan_ball wrote:

@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!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings