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.

#!/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....

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.

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

the error is

./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:

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

Secondly, your construct:

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

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

Hence the error:

 
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:

 
#!/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

There is work.....thanks a lot..... :b: