Guest User

Untitled

a guest
Nov 17th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Declare Variables
  4.  
  5. # This is the name of the Jamf Pro Account that has priviges for the API. Note this should be limited
  6. apiuser=""
  7.  
  8. # This is the password of the Jamf Pro Account that has priviges for the API. Note this should be limited
  9. apipass=""
  10.  
  11. # This is the Jamf Pro URL
  12. jamfurl=""
  13.  
  14. # This will set a default Prefix for a computer name
  15. prefix="EDU"
  16.  
  17. # hardcode Serial Number Variable
  18. serialNumber=""
  19.  
  20. # Get Serial Number
  21. serialNumber="$(system_profiler SPHardwareDataType | awk '/Serial Number/{print $4}')"
  22.  
  23. # Get the Current Assigned User
  24. User=$(curl -su "$apiuser":"$apipass" -H "Accept: application/xml" "$jamfurl"JSSResource/computers/serialnumber/"$serialNumber" | xmllint --xpath '/computer/location/username/text()' -)
  25.  
  26. # Get assigned Building
  27. Building=$(curl -su "$apiuser":"$apipass" -H "Accept: application/xml" "$jamfurl"JSSResource/computers/serialnumber/"$serialNumber" | xmllint --xpath '/computer/location/building/text()' -)
  28.  
  29. # Check to see if a user is assigned, if not, exit script using error code 1
  30. if [[ "$User" == "" ]]; then
  31. echo "User not assigned to computer record"
  32. exit 1
  33. fi
  34.  
  35. # Check to see if a building is assigned, if not, exit script using error code 2
  36. if [[ "$Building" == "" ]]; then
  37. echo "Building not assigned to computer record"
  38. exit 2
  39. fi
  40.  
  41. # Set Variable for naming computer
  42. computerName=$(echo "$prefix-$Building-$User")
  43.  
  44. # Set Computer Name
  45. sudo scutil --set HostName "$computerName"
  46. sudo scutil --set LocalHostName "$computerName"
  47. sudo scutil --set ComputerName "$computerName"
  48.  
  49. echo "$computerName"
Add Comment
Please, Sign In to add comment