Extension Attribute using LDAP field - append to string

guidotti
Contributor II

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 2

davidacland
Honored Contributor II
Honored Contributor II

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

guidotti
Contributor II

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