First of all thanks to Venky for giving the space to post this blog.
There may be a scenario in which you want to get the data from the LDAP server and manipulate it. LDAP server is a Light weight Data Protocol used for user authentication remotely.
/usr/gsa/bin/ldapsearch -h xxx.yyy.com -b o=yyy.com uid=$ID$COUNTRY
Above is the command “ldapsearch” in which you will be giving the xxx.yyy.com has the LDAP server name. For more on LDAP please visit the link below http://ressukka.net/2001/06/ldap/
when run the above command you will get the output similar to
dn: cn=Imogen, ou=#linux, ou=irc, dc=example, dc=net
cn: Imogen
objectclass: top
modes: bfo
laston: 960852116 #Linux
xtra: created 960300295
There is a unique ID (uid) given to ldapsearch as the arguement which is user_Id and Country_Id in my environment.
The script below parses the ID and Country Code from /etc/passwd and updates the gecos field, where you can check by running the command — lsuser -a gecos user_name. This was tested on AIX machine. Updating the gecos field is just one simple application. By modifying it slightly we can also use it on Linux.
#!/usr/bin/perl
#use strict;
use warnings;
my $args = @ARGV;
if($ARGV[0] eq “”){
print “please enter password file as argument\n”;}
open my $fh, ‘<’ , $ARGV[0] or die “Could not open ‘$ARGV[0]‘: $!”;
while(my $line = <$fh>){
if($line =~ m/:/ && $line =~ m/;/){
@PASS = split(/:/, $line);
@PASS2 = split(/;/ , $PASS[4]);
#print “$PASS2[1]\n”;
chomp($PASS2[1]);
@PASS3 = split(/\//, $PASS2[1]);
#print “$PASS3[0] $PASS3[2]\n”;
my $id = $PASS3[2];
my $country = $PASS3[0];
$country =~ s/^\s+//; #white spaces removed
$id =~ s/\s+$//; #white spaces removed
bluefind($id,$country);
}
elsif($line =~ m/,/ && $line =~ m/:/) {
@NPASS = split(/,/,$line);
@NPASS1 = split(/:/,$NPASS[1]);
@NPASS2 = split(/\//,$NPASS1[0]);
#print “@PASS2\n”;
$NPASS2[0] =~ s/^\s+//;
$NPASS2[2] =~ s/\s+$//;
bluefind($NPASS2[2],$NPASS2[0]);
}
}
sub bluefind{
my ($ID,$COUNTRY) = @_;
my $NAME=”";
my $EMPT=”";
my $MAIL=”";
$NAME = `/usr/gsa/bin/ldapsearch -h xxx.yyy.com -b o=yyy.com uid=$ID$COUNTRY cn |grep ^cn|head -1`;
$NAME = substr($NAME, 4, );
chomp($NAME);
$EMPT = `/usr/gsa/bin/ldapsearch -h xxx.yyy.com -b o=yyy.com uid=$ID$COUNTRY employeetype|grep ^employeetype`;
$EMPT = substr($EMPT, 14, );
chomp($EMPT);
$MAIL = `/usr/gsa/bin/ldapsearch -h xxx.yyy.com -b o=yyy.com uid=$ID$COUNTRY mail |grep ^mail|head -1`;
$MAIL = substr($MAIL, 6, );
chomp($MAIL);
if( $NAME eq “” ){
open (NOUSER, ‘>>./notfound.out’);
print NOUSER “@PASS[0] –>$ID $COUNTRY Not found in bluepages\n”;
close (NOUSER);
}
else{
open (GECOS, ‘>>./gecos_update.ksh’);
print GECOS “chuser gecos=\”$NAME; $COUNTRY/$EMPT/$ID ;$MAIL\” @PASS[0]” . “\n”;
close (CHUSER);
}
print “$NAME $EMPT $MAIL @PASS[0]\n”;
}
close $fh;


good and great script. I was looking for such a script to pull the data from my LDAP server and reformat the
data to push it to FTP server. I’m just tweaking above one to fit for linux server. Is there any way to integrate
with NIS.
David I do not know much about NIS only I know is it same like LDAP but mainly used user authentication
on linux boxes. think command line utilities are available for NIS.
This article will assist the internet users for creating new weblog or even a blog from start
to end.