Skip to main content
Question

Using the Department and Building names in a script

  • June 13, 2019
  • 1 reply
  • 0 views

Forum|alt.badge.img+1

Hello,

I'm wanting to run a script which does different things based on the computers Building and/or Department.

For example, I use Munki also for managing specific apps that are a lot easier to deploy and update using Munki than they are using Jamf (sorry Jamf)... As a result, I would like to run a script on the concept of "If Department = Audio then set Munki Manifest to Audio"

Yes, I know I could simply write a script to set the manifest to Audio and only scope it to Audio Department, but I'd have to create an individual script for each department, then create a policy for each script and scope them accordingly - This is time consuming and adds clutter so would like one policy that runs on all computers, and I scope it to all departments so this would be much easier.

1 reply

Forum|alt.badge.img+13
  • Valued Contributor
  • 268 replies
  • June 13, 2019

You can get that info from the API and use it in your script like so:

#!/bin/bash

API_URL=https://your.jamf.url/JSSResource
API_USER=user_with_read_permissions
API_PASS=PaSsWoRd

# Get serial number
myserial=$(system_profiler SPHardwareDataType | awk '/Serial Number/{print $4}')

# Get department
department=$(curl -sku "$API_USER":"$API_PASS" 
-X GET 
-H "accept: text/xml" 
"$API_URL"/computers/serialnumber/$myserial | xmllint --xpath '/computer/location/department/text()' -)

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