Wednesday April 18, 2007

If you're inside Sun (or other companies that deploy LDAP name services) you may have tried to use the ldap_client utility from the command line, but found it too low level. I made up a little shell function that I've been using for a few years now, and it's served me well. You can get some of the same information using the Address Book in Thunderbird, or whatever mailer you might be using, but if you want more fields to be available, it's better to drill down the raw LDAP database. If you remove the list of fields from the command line to ldap_client, it will show all the available fields. The finger command at the end of my script doesn't do much anymore since Solaris leaves the finger daemon off by default.
name_lookup() {
# 'l' means location I guess
fields="uid host telephonenumber preferredrfc822recipient"
fields="$fields photourl l rfc822recipient globallocation roomnumber"
if [ $# = 2 ];
then
# Xyz's givenname=xyz nickname=123
# filter="(&(|()(givenname=$1*))(surname=$2*))"
filter="(&(|(givenname=$1*)(nickname=$1*))(surname=$2*))"
elif [ $# = 1 ];
then
filter="uid=$1"
else
echo Too many arguments, use one or two.
fi
# echo ldapsearch -h sun-ds -b dc=sun,dc=com $filter ${fields}
output="$(ldapsearch -h sun-ds -b dc=sun,dc=com $filter ${fields})"
output="$(echo "$output" | \
sed -e 's/preferredrfc822recipient/email/' \
-e 's/^cn=\([^(]*\).*/\1/' \
)"
echo
echo "$output"
host=$(echo "$output" | grep 'host=' | sed 's/host=//' )
# host=$(echo "$output" | sed 's/.*host=\([^ ]*\).*/\1/')
echo host is $host
finger @$host
echo
}
name() { name_lookup "$@"; }
Here's the output for me (phone number xxx'ed out, natch). And my host
name is a few years out of date. I need to update it in netadmin....
% name chr quen
version: 1
dn: cn=Christopher Quenelle (23484),ou=people,dc=sun,dc=com
uid: quenelle
host: veldt.eng.Sun.COM
telephonenumber: x8xxxx/650-786-XXXX
email: Chris.Quenelle@Sun.COM
photourl: http://dptwiki.sfbay/~quenelle/web-head.jpg
l: MENLO PARK,UNITED STATES
rfc822recipient: Chris.Quenelle@Sun.COM
rfc822recipient: Chris.Quenelle@SFBay.Sun.COM
globallocation: mpk16
roomnumber: 3148
host is
unknown host:
gnome kstats From the department of <Projects I Wish I Had Time To Work On> comes this gem. There are jillions of clever applets that I can put on the Gnome panel, and there are lots of APIs (perl, java, etc) that I can use to access Solaris kstats. So why hasn't anyone put the two together yet? There's even a GUI available for kstats. It would be cool to start with some other charting applet (like this one), or you could start with the System Monitor applet that's already there. and hook it up to to kstats data from the Solaris kernel. It would really show of the observability features of Solaris in a way that the average user can understand.
Posted by Chris Quenelle
( Apr 18 2007, 03:28:06 PM PDT )
-
Permalink
-
Comments [2]
-
OpenSolaris
Older blog entries: