Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-07-2012
Registered User
 

Join Date: Dec 2011
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
Unhappy Expired user alert

Dear Expert,
I have made a script for check the expired user and it will send alert if the password will expire less than 8 days.

Code:
#!/bin/ksh
# Script for check who will expired the password
#
currentdate=`perl -le 'print time'`
changeperiod=`echo $((84*86400))`
remindperiod=`echo $((8*86400))`
alertperiod=`echo"($changeperiod - $remindperiod)"`
lastchange=`awk '/:/ {name=$1} ; /lastu/ {print name $3}' /etc/security/passwd`

for user in $lastchange
do
username=`echo $user | cut -f 1 -d:`
lastupdate=`echo $user | cut -f 2 -d:`
alertdate=`echo "$alertperiod + $lastupdate" | bc`
expireddate=`echo "$changeperiode + $lastupdate" | bc`
  if [$alertdate -le $currentdate]; then
      echo $username " "`perl -le "print scalar localtime ($expireddate)"` > /home/user3/expireduser.txt
  fi
done

but the script error. Please help me....
Sponsored Links
    #2  
Old 02-07-2012
Registered User
 

Join Date: Jun 2011
Posts: 65
Thanks: 6
Thanked 14 Times in 14 Posts
Quote:
Originally Posted by michlix View Post
Dear Expert,
I have made a script for check the expired user and it will send alert if the password will expire less than 8 days.
but the script error. Please help me....

And if you can please pass on the output / error of the script, don't you think it may help the people around to give the solution steadfast?

Secondly, I could run the script that you posted above, but the passwd file is not there in my system.


Code:
 
# ls -ltr /etc/security/passwd
ls: /etc/security/passwd: No such file or directory

Sponsored Links
    #3  
Old 02-07-2012
Registered User
 

Join Date: Dec 2011
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by knight_eon View Post
And if you can please pass on the output / error of the script, don't you think it may help the people around to give the solution steadfast?

Secondly, I could run the script that you posted above, but the passwd file is not there in my system.


Code:
 
# ls -ltr /etc/security/passwd
ls: /etc/security/passwd: No such file or directory

the error is

Code:
./scriptalertpasswd.sh[7]: echo(7257600 - 691200):  not found.
syntax error on line 1 stdin
./scriptalertpasswd.sh[16]: test: 0403-021 A ] character is missing.
syntax error on line 1 stdin
./scriptalertpasswd.sh[16]: test: 0403-021 A ] character is missing.
syntax error on line 1 stdin
./scriptalertpasswd.sh[16]: test: 0403-021 A ] character is missing.

    #4  
Old 02-07-2012
Registered User
 

Join Date: Jun 2011
Posts: 65
Thanks: 6
Thanked 14 Times in 14 Posts
Quote:
Originally Posted by michlix View Post
the error is

Code:
./scriptalertpasswd.sh[7]: echo(7257600 - 691200):  not found.
syntax error on line 1 stdin
./scriptalertpasswd.sh[16]: test: 0403-021 A ] character is missing.
syntax error on line 1 stdin
./scriptalertpasswd.sh[16]: test: 0403-021 A ] character is missing.
syntax error on line 1 stdin
./scriptalertpasswd.sh[16]: test: 0403-021 A ] character is missing.

Are you trying to compute the difference in alertperiod=`echo"($changeperiod - $remindperiod)"`
If that is the case:


Code:
# changeperiod=7257600
# remindperiod=691200
# alertperiod=`echo"($changeperiod - $remindperiod)"`
-bash: echo(7257600 - 691200): command not found
# alertperiod=$((changeperiod - $remindperiod))
# echo $alertperiod
6566400

Secondly, your construct:

Code:
expireddate=`echo "$changeperiode + $lastupdate" | bc`

Can you see the extra e that is in bold appended to changeperiod variable? That is causing the pain

Hence the error:


Code:
 
scriptalertpasswd.sh[16]: test: 0403-021 A ] character is missing.
syntax error on line 1 stdin
./scriptalertpasswd.sh[16]: test: 0403-021 A ] character is missing.

Make the code like this:


Code:
 
#!/bin/ksh
# Script for check whose password will expire in 8 days
#
currentdate=`perl -le 'print time'`
changeperiod=$((84*86400))
remindperiod=$((8*86400))
alertperiod=$((changeperiod - remindperiod))
lastchange=`awk '/:/ {name=$1} ; /lastu/ {print name $3}' /etc/security/passwd`
for user in $lastchange
do
username=`echo $user | cut -f 1 -d:`
lastupdate=`echo $user | cut -f 2 -d:`
alertdate=$((alertperiod + lastupdate)) #" | bc`
expireddate=$((changeperiod + lastupdate)) #" | bc`
  if [$alertdate -le $currentdate]; then
      echo $username " "`perl -le "print scalar localtime ($expireddate)"` > /home/user3/expireduser.txt
  fi
done

Sponsored Links
    #5  
Old 02-08-2012
Registered User
 

Join Date: Dec 2011
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
There is work.....thanks a lot.....
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to write a shellscript to send a mail alert to the website user based on license expiration time deepu_Shscripts Shell Programming and Scripting 0 09-03-2010 02:55 AM
user expired murad.jaber Solaris 2 10-11-2007 04:14 AM
How to reactivate expired account in Linux as a root user cy163 UNIX for Dummies Questions & Answers 2 05-14-2007 08:46 AM
HMC User account expired - What now? backslash AIX 0 05-31-2006 05:14 PM
Sending a message to a user when password will be expired Diederd Security 1 01-28-2002 05:00 PM



All times are GMT -4. The time now is 04:35 AM.