Okay so I'm really new to perl but I've hacked together this program to
parse /etc/passwd and email the login's manager every month. Well it
does just that but now I need to add some widget that will email the
manager once with a list of all his personnel rather than one email per
user in the passwd file. I am at a standstill. help!
this script assumes the passwd file is formatted a certain way...
ie
bob:x:1001:10:bob.smith,big.cheese,4449999:/export/home/bob:/bin/ksh
with big.cheese being the manager...
here is the code...edited to protect the guilty....
#!/usr/bin/perl
#
#Script parses /etc/passwd and emails all users managers requesting
status of subject user
#
#
#
############################################################################
open(OUTPUT, "hostname|") || die "Can't stat hostname";
$hostname=<OUTPUT>;
close(OUTPUT);
############################################################################
# setup array of excluded system users (ie. peeps who don't have
managers)
############################################################################
@exuser= ("root", "daemon", "bin", "sys", "adm", "lp", "uucp", "nuucp",
"listen", "nobody", "noaccess", "nobody4");
############################################################################
# read passwd file into array so weez can chunkonit
############################################################################
open (F, "/etc/passwd") || die "Could not open passwd file: $:";
@password=<F>;
################################################################################
# perform the magic filtering necessary to pick out the names from the
comment
# field and email the managers requesting status of the user.
################################################################################
foreach $line (@password)
{
( $login, $pass, $uid, $gid, $Comm, $dir, $shell ) = split (/:/,
$line);
@User = split (/,/, $Comm);
if (1 == scalar ( @User ))
{
next;
}
if ( $Comm eq "" )
{
next;
}
print "login=$login User=@User\n";
if ( 1 != grep ( /$login/, @exuser ) )
{
chomp ( $hostname );
open( MAIL, "| /bin/mailx -s \"User Access\" -U $User[1]\@hotmail.com"
);
print MAIL <<"_END_OF_FILE_";
Does $User[0] still require access to server $hostname?
Please respond to my Team.
_END_OF_FILE_
}
}
thanks in advance for any help you can provide...