TimeZone Extension Attribute

user-dKGrgHyYDI
New Contributor

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! 

1 ACCEPTED SOLUTION

addikt42
New Contributor

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. 

 

 

View solution in original post

4 REPLIES 4

spsingh
New Contributor

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.

sgiesbrecht
Contributor III

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

Thx for the script

lsv
New Contributor III

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

Ideally going for a more generic grouping than specific locations.

addikt42
New Contributor

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.