[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: (VERY OT) Date last logged in
Here is mine.
By now way I can consider myself a perl hacker (not even begginer) but I managed to get the results I needed.
I used the passwd file to get the usernames and since we use NIS I removed the + in front of the username to be able to pass it across all my servers.
./last.pl $INPUT_FILE > $REPORT_FILE
I hope it helps.
Eric Berthiaume
maverick@up2.com
---------------------------------------------
last.pl
---------------------------------------------
#!/usr/local/bin/perl
#
#
#
#
# This script outputs the last time a user,
# from the nis password file given on input,
# as log on.
#
# The output is then sorted in order of the
# less used accounts.
#
#
#
#
# get today's date, if somebody is still logged
# in it will show as last logged on today's date.
#
open(DATE, "date '+%b %d'|");
while(<DATE>) {
($todaymonth, $todayday) = (split m/\s+/)[0,1];
}
#
# get the last wtmp date, it should be 3 month.
#
open(WTMP, "last -1 bobo|");
while(<WTMP>) {
($monthwtmp, $daywtmp) = (split m/\s+/)[3,4];
}
#
# Perform the split on the passwd file.
# Remove the + from the username.
# Print the output.
#
while(<>) {
($Name, $Pass, $Gcos) = (split /:/)[0,1,4];
($Name) =~ s/^\+//;
if ($Pass =~ /^\*$/) { last; }
open(LAST, "last -1 $Name|");
while(<LAST>) {
if (/still/) {
print "$Name $Gcos last logged on $todaymonth $todayday\n";
}else{
($username, $lastmonth, $lastday) = (split m/\s+/)[0,3,4];
if (/^\W/) {
print "$Name $Gcos never logged since $monthwtmp $daywtmp\n";
}else{
print "$username $Gcos last logged on $lastmonth $lastday\n";
}
}
close(LAST);
}
}
close(DATE);
close(WTMP);
On Mon, Apr 30, 2001 at 11:45:44PM -0500, InSaNe wrote:
> I am trying to find a way to write a shell/perl/c program/script that will
> finger a user(or something else that works) and determine if they haven't
> logged in for more than 3 months...
>
>
> Like have it go through /home and then output a list of people who haven't
> logged in withing 3 months, I am trying to delete inactive accounts.
> Sadly, my poor beginner PERL skills just don't cut it.