So you know how sometimes you're trying to get the highest uidNumber in OpenLDAP?  You know, especially when adding new users and trying to figure out the latest uidNumber to assign to them?  I searched Google high and low to figure out this while working on my implementation of "adduser" scripts in BASH and people were talking about odd Perl hackery and such.  Well one time it hit me: Why not use awk?

This simple one liner with pipes will get you the highest/last uidNumber:

[bash]ldapsearch -H ldaps://domain -D "cn=admin,dc=domain,dc=com" -w password | awk '/uidNumber: / {print $2}' | tail -n 1
[/bash]

This will dump the largest uidNumber which you could then increment  in your shell script.  Of course, this snippet might not be practical in a Perl script, but you can always get the script to call out a shell script and get it that way.


Comments

comments powered by Disqus