#!/usr/local/bin/perl # # autowarn # v .01 # # this should be run every nite by cron. # # it will scan all the accounts in /etc/shadow and # for any that have exactly (10,30,etc) days left before # expiring, it will send an email to those accounts with # a warning. # # miff, 2000 # #this whole deal is gonna be a simple subtraction of the system # date from the expir date (since the expir date is in days) # in "days since 1970" #set some constants: $file_of_interest = '/etc/shadow'; $secs_per_day = 86400; #set today: $today = int(time / $secs_per_day); print "autowarn expiration date checker by miff\n\n"; print "today appears to be $today in system time... \n"; open (SHADOW, $file_of_interest) || die "big problems opening $file_of_interest\n\n"; while ($input = ) { chomp $input; @fields = split (":",$input); if ($fields[7]) { # we have an expiration date print "user $fields[0], expiration date (machine time) = $fields[7] \n"; $days_till_expiry = int($fields[7]) - $today; $message = "System autowarn: Your account will expire in $days_till_expiry days! \n\n"; if ($days_till_expiry == 10) { print "10 days left for $fields[0]\n"; system("echo '$message' | mail $fields[0]"); } elsif ($days_till_expiry == 30) { print "30 days left for $fields[0]\n"; system("echo '$message' | mail $fields[0]"); } elsif ($days_till_expiry == 5) { print "5 days left for $fields[0]\n"; system("echo '$message' | mail $fields[0]"); } elsif ($days_till_expiry == 1) { print "1 day left for $fields[0]\n"; } } } close (SHADOW);