Skip to main content
Solved

TimeZone Extension Attribute

  • September 25, 2021
  • 4 replies
  • 44 views

Forum|alt.badge.img+1

I couldn't find any extension attribute in the templates or in any forum for showing the local timezone of a computer in jamf, so I wrote my own.

 

It's just a simple script to pull the info from the localtime file, and cut off the first part that is always the same, then return the result to the jss.

 

example: TimeZone:/America/New_York

 

Script:

#!/bin/bash # Extension attribute to return current TZ localtime=`/bin/ls -n /etc/localtime` TimeZone=${localtime:79} echo "<result>$TimeZone</result>" exit 0

 

Here's the full .XML file for importing to jamf directly:

<?xml version="1.0" encoding="UTF-8"?><extensionAttribute> <displayName>TimeZone</displayName> <description>gets time zone</description> <dataType>string</dataType> <scriptContentsMac>#!/bin/bash&#13; &#13; # Extension attribute to return current TZ&#13; &#13; localtime=`/bin/ls -n /etc/localtime`&#13; &#13; TimeZone=${localtime:79}&#13; &#13; echo "&lt;result&gt;$TimeZone&lt;/result&gt;"&#13; &#13; exit 0&#13; </scriptContentsMac> </extensionAttribute>

Feel free to use as needed! 

Best answer by addikt42

I changed this slightly to pipe this to awk

 

#!/bin/bash # Extension attribute to return current TZ localtime=`/bin/ls -n /etc/localtime | awk -F"zoneinfo/" '/zoneinfo/{print $2}'` echo "<result>$localtime</result>" exit 0

 

awk instead. 

 

 

4 replies

Forum|alt.badge.img
  • New Contributor
  • September 27, 2021

The digital transformation consultant improves organization efficiency by implementing Enterprise software (ERP, CRM, HR, CX, HCM, business intelligence). We implement ERP solutions that enhance customer experience, improve efficiency and skyrocket growth. Our objective is to deliver ERP solutions that increase ROI and minimize risk. If You need ERP consultant then contact us.


Forum|alt.badge.img+10
  • Valued Contributor
  • September 27, 2021

I was talking with my co-worker about this on Friday.  Were you listening @user-dKGrgHyYDI like Alexa? 😁

Thx for the script


Forum|alt.badge.img+4
  • Contributor
  • January 28, 2022

Is there a way to get the specific time zone? (i.e. EST, PST)

Ideally going for a more generic grouping than specific locations.


Forum|alt.badge.img+6
  • New Contributor
  • Answer
  • April 19, 2022

I changed this slightly to pipe this to awk

 

#!/bin/bash # Extension attribute to return current TZ localtime=`/bin/ls -n /etc/localtime | awk -F"zoneinfo/" '/zoneinfo/{print $2}'` echo "<result>$localtime</result>" exit 0

 

awk instead.