I found this thread from TEK-TIP user Columb. I am real new to scripting and perl,(just figured how to spell it) and was wanting a little help in understanding this script and modfying it to not mail the users but mail me.
Here is the script:
#! /usr/bin/perl -w
use strict;
open FH, "/etc/passwd";
while (<FH>)
{
my ( $uname, undef, $uid ) = split /:/;
$uid > 100 and push @helpdesk, $uname;
}
close FH;
my @helpdesk = qw ;
my $exptime = 56
my $warntime = 42
my $secs_in_day = 60 * 60 * 24;
my $now = int ((time)/($secs_in_day));
my $host = `uname -n`;
chomp $host;
foreach my $user ( @helpdesk )
{
system "lsuser $user >/dev/null 2>&1" and (print STDERR "$user not on system\n
"), next;
my $chtime = `lssec -f /etc/security/passwd -s $user -a lastupdate`;
$chtime =~ s/^.*?=(\d+)/$1/;
$chtime or (print STDERR "$user has nver been updated\n"), next;
$chtime = int ($chtime/$secs_in_day);
$chtime = $now - $chtime;
$chtime < $warntime and next;
$chtime > $exptime and (system "echo Your password on $host has expired - Contact Unix support to reset | mail -s \"Password on $host\" \" $user\@mailserver"), next;
$chtime = 56 - $chtime;
system "echo Your password on $host will expire in $chtime days - please log i
n and reset it | mail -s \"Password on $host\" $user\@mailserver";
}
Thanks to all that take there time to help. I know that TIME is one of those valuable commodities that get taken advantage of!
Here is the script:
#! /usr/bin/perl -w
use strict;
open FH, "/etc/passwd";
while (<FH>)
{
my ( $uname, undef, $uid ) = split /:/;
$uid > 100 and push @helpdesk, $uname;
}
close FH;
my @helpdesk = qw ;
my $exptime = 56
my $warntime = 42
my $secs_in_day = 60 * 60 * 24;
my $now = int ((time)/($secs_in_day));
my $host = `uname -n`;
chomp $host;
foreach my $user ( @helpdesk )
{
system "lsuser $user >/dev/null 2>&1" and (print STDERR "$user not on system\n
"), next;
my $chtime = `lssec -f /etc/security/passwd -s $user -a lastupdate`;
$chtime =~ s/^.*?=(\d+)/$1/;
$chtime or (print STDERR "$user has nver been updated\n"), next;
$chtime = int ($chtime/$secs_in_day);
$chtime = $now - $chtime;
$chtime < $warntime and next;
$chtime > $exptime and (system "echo Your password on $host has expired - Contact Unix support to reset | mail -s \"Password on $host\" \" $user\@mailserver"), next;
$chtime = 56 - $chtime;
system "echo Your password on $host will expire in $chtime days - please log i
n and reset it | mail -s \"Password on $host\" $user\@mailserver";
}
Thanks to all that take there time to help. I know that TIME is one of those valuable commodities that get taken advantage of!