Skip to main content
Question

Extension Attribute using LDAP field - append to string


Forum|alt.badge.img+18

Hey, all.

I am using an extension attribute to collect "cost center" information for each device (based on user ID that the devices are assigned to). It uses the "Department" LDAP attribute for my organization, which is synced from Peoplesoft initially. What ends up happening is I get a 3 or 4 digit number. To make it match the rest of the organization's naming scheme, I need to have 6 digits always. So if the cost center is 3 digits, it should append 3 zeroes (000738). If it is two digits, it should append four zeroes (004565). If it is 6 digits, it should show the 6 digits (59F42Z). I am unsure how to take the current extension attribute and add those leading zeroes. I am guessing I need to change it to run a script instead of the direct LDAP pull.

Any help is appreciated.

Thanks!

2 replies

davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • 1811 replies
  • July 6, 2016

printf will do that for you:

# run the code to save Department value from LDAP as a variable called (for example) "ldapinput"

ldapoutput=$(printf %06d $ldapinput)

echo "<result>$ldapoutput</result>"

exit 0

Forum|alt.badge.img+18
  • Author
  • Valued Contributor
  • 127 replies
  • July 6, 2016

Ah, an elegant answer. I neglected the capabilities of printf :)
Thank you! I'll give it a shot now.


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