Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Sync passwd and AD users full names

by TechFly (Scribe)
on Jul 28, 2010 at 16:03 UTC ( #851743=CUFP: print w/ replies, xml ) Need Help??

I have been tasked with cleaning up the AIX boxes. One of the things I wanted to do was add the users full names to the passwd file so that I can figure out who users are fairly easily. I did not want to do this manually, so here is a script I came up with to do it for me. It takes the passwd in the same folder as the script, and creates a file that you can then replace the old passwd with.

#!/usr/bin/perl -w =head1 Author: TechFly Name: Description: Add the uses names from AD into the passwd file. The scr +ipt will read the passwd file in the same directory, and then connect + to AD. It will use the usernames in the passwd file to look up the +users full name in AD, then populate that in a file. It a +lso creates a nousername file that is populated with the users not fo +und in AD. Start date: 7-23-2010 Last updated Date: 7-23-2010 =cut use strict; use warnings; use Net::LDAP; #for subroutine getADInfo my $ldap; my $mesg; my $entry; my @entries; my $username; my $userfullname = ""; #for main routine my $fileinname = "./passwd"; my $filein; my $fileoutname = "./"; my $fonousername; my $fonousernamename = "./nousername"; my $userline; my @users; my $fileout; my $userlineout; open($filein, "<", $fileinname) || die $!; open($fileout, ">>", $fileoutname) || die $!; open($fonousername, ">>", $fonousernamename) || die $!; while($userline = <$filein>){ @users = split /:/, $userline; $username = $users[0]; getADInfo(); print $fonousername ("$username\n") if $userfullname eq ""; print($username." - ".$userfullname."\n"); $users[4] = "$userfullname"; chomp($userlineout = join ":", @users); print $fileout ("$userlineout\n"); $userfullname = ""; } close $filein; close $fileout; sub getADInfo{ $ldap = Net::LDAP->new("", onerror=>'w +arn'); $mesg = $ldap->bind( "cn=some,cn=domain,cn=com", password => "somepass +word" ); $mesg = $ldap->search( base => "cn=some,cn=domain,cn=com", filter => "sAMAccountName=$username", scope => 'sub', sizelimit => '0', attrs => ['name'] ) || die $!; @entries = $mesg->entries; foreach $entry(@entries){ #print($entry->get_value('name')."\n"); $userfullname = $entry->get_value('name'); }}

Comment on Sync passwd and AD users full names
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://851743]
Approved by ww
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2015-10-09 23:04 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (253 votes), past polls