Extension Attribute using LDAP field - append to string

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
07-06-2016
07:51 AM
- last edited on
03-04-2025
05:53 AM
by
kh-richa_mig
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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 07-06-2016 09:45 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 07-06-2016 10:41 AM
Ah, an elegant answer. I neglected the capabilities of printf :)
Thank you! I'll give it a shot now.
