Expired user alert


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expired user alert
# 1  
Old 02-07-2012
Data 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....
# 2  
Old 02-07-2012
Quote:
Originally Posted by michlix
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

# 3  
Old 02-07-2012
Quote:
Originally Posted by knight_eon
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
Quote:
Originally Posted by michlix
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 Smilie

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

# 5  
Old 02-08-2012
There is work.....thanks a lot..... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Solaris

Solaris 11 user account login expired

Hi everyone Please i need urgent help... I have installed solaris 11 using live media.. then i installed sunray.. every thing is fine.. but after system reboot i am unable to login on server on GUI it gives account expired error or some time authentication failed... but i can log in through... (11 Replies)
Discussion started by: amk
11 Replies

2. Shell Programming and Scripting

Finding AIX user accounts expired or locked

// AIX 6.1 In need of finding which AIX user accounts will be expired and are locked. I have placed the following parameters under /etc/security/user... (1 Reply)
Discussion started by: Daniel Gate
1 Replies

3. Solaris

user expired

dear all iam trying to make user expire and it not suceeded with me iam trying useradd -e and it not succeeded (2 Replies)
Discussion started by: murad.jaber
2 Replies

4. UNIX for Dummies Questions & Answers

How to reactivate expired account in Linux as a root user

I am an administrator of a Red Hat Enterprise Linux system. Now one account expired. I wonder how to reactivate the account. Thanks (2 Replies)
Discussion started by: cy163
2 Replies

5. AIX

HMC User account expired - What now?

I've created an hmc user account for our developers and set a pawword expiry to 30 days. Trouble is when the password expires they are asked to change it in the WebSM gui but it returns an error "XXXX check log file /var/websm/data/....log" which doesn't exist. I've tried resetting the password... (0 Replies)
Discussion started by: backslash
0 Replies

6. Cybersecurity

Sending a message to a user when password will be expired

Hi, Does anyone have a script (for AIX) that sends a message to a user that his password will be expired within 5 days for ex. Thanks (1 Reply)
Discussion started by: Diederd
1 Replies
Login or Register to Ask a Question