Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password expiration script 1

Status
Not open for further replies.

bcre3306

MIS
May 7, 2002
45
US
Is there any way to have a script run so when a user logs in that it will check when there password is going to expire and if it is within a certain time frame it would cause a popup window on there windows terminal? Any help or suggestions would be greatly appreciated!
 
It's not what you asked for but this is my answer to that problem
Code:
#! /usr/bin/perl -w
use strict;
 
my @helpdesk = qw ( user1 user2 user3 );
 
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 < 42 and next;
  $chtime > 56 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";
  }

Columb Healy
 
when does this notify the user...how early before the password expires?
 
On our system the password expires in 56 days. The script sends a warning after 42 days.

To make the script more manageable add
Code:
my $exptime = 56
my $warntime = 42

Then change
Code:
  $chtime < 42 and next;
  $chtime > 56 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;

to

Code:
  $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 = $exptime - $chtime;

Yo may notiece that I list the users. This could be replaced by
Code:
open FH, "/etc/passwd";
while (<FH>)
  {
  my ( $uname, undef, $uid ) = split /:/;
  $uid > 1000 and push @helpdesk, $uname;
  }
close FH;
which will list all users with an ID > 1000
You might also want to use a more meaningfull name for the user array. @helpdesk shows that this was written for the Helpdesk users. Others look after themselves!

I hope this helps

Columb Healy
 
ok I have that working but I have one more request and since I don't know perl programming I am at a loss. I want to use smbclient to do windows popups for the user to tell them there password is expiring. I have it working if I hard code the ip address of the machine but I want the scipt to scrape the ip address from who am i or something like that. Any help would be greatly appreciated.
 
This code uses the output from who
Code:
#!/bin/perl -w
use strict;
 
my $secs_in_day = 60 * 60 * 24;
my $now = int ((time)/($secs_in_day));
my $host = `uname -n`;
chomp $host;
 
foreach ( `who` )
  {
  my ($uhost, $user)
  /^(\w+).*\((.*)\)/ and $user = $1, $uhost = $2 or 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 < 42 and next;
  $chtime > 56 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";
  }
I don't use or know smbclient but the variable $uhost has the users ipaddress in it. So if the smbclient command was
Code:
smbfoo <username> <ipaddress>
then the system call in the perl script would be
Code:
system "smbfoo $uname $uhost";
I hope this helps

Columb Healy
 
Sorry to be a pain but this is not working for me. I keep getting this when I run it.

syntax error at ./passtest1.ksh line 12, near "/^"
Bareword "w" not allowed while "strict subs" in use at ./passtest1.ksh line 12.
Unquoted string "w" may clash with future reserved word at ./passtest1.ksh line 12.
Backslash found where operator expected at ./passtest1.ksh line 12, near "*)\"
(Missing operator before \?)
Global symbol "$user" requires explicit package name at ./passtest1.ksh line 12.
Global symbol "$uhost" requires explicit package name at ./passtest1.ksh line 12.
Execution of ./passtest1.ksh aborted due to compilation errors.
 
Sorry - I can't test the amended version without mass mailing all my users so I had to debug by eye and there's a missin semi-colon which should be at the enc of
Code:
  my ($user, $uhost);

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top