Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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'); }}

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://851743]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2018-02-21 07:52 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (276 votes). Check out past polls.