Operating System - HP-UX
1833314 Members
2904 Online
110051 Solutions
New Discussion

script to mail passwd expire date

 
SOLVED
Go to solution
M.Thomas
Frequent Advisor

script to mail passwd expire date

Dear Admins,

I want to write a script for the following task

Check & notify user when the password will expire (some user may not login for anything but they will check there mail, so they need to be provided this information via mail. Otherwise, the root user will have to set their passwd each time they expire.)

Please guide me how to do this.

Thanks in advance

Regards
Thomas
5 REPLIES 5
Steven Schweda
Honored Contributor

Re: script to mail passwd expire date

You've posted the same question in an HP-UX
forum and a Tru64 forum. Perhaps you should
say which OS you're actually running.
Hasan  Atasoy
Honored Contributor
Solution

Re: script to mail passwd expire date

hi thomas ,
belwo script check username and send mail if expiration time is less than 15 day. it need perl . you can customize accoding your needs.

#!/usr/bin/sh

set -u
PATH=/usr/bin:/usr/sbin:/usr/lbin

integer exp_time
integer exp_date
integer current_time
integer last_change
integer time_left
integer days_left
integer seconds_per_day=86400
integer user_aging

user_aging=$(/usr/lbin/getprpw -r -m exptm $LOGNAME)

U=$(echo $LOGNAME|cut -c 1)

exp=$(logins -x -l $LOGNAME | tail -1 | awk '{print $4}')
((exp_time = exp * 86400))
current_time=$(/opt/perl/bin/perl -e "print time")

last_change=$(grep u_succhg /tcb/files/auth/$U/$LOGNAME | \
awk -F "u_succhg#" ' {print $2}' |\
awk -F ":" ' {print $1}' )

((exp_date = last_change + exp_time))
((time_left = exp_date - current_time))
((days_left = time_left / seconds_per_day))

last_change_date=$(getprpw -r -m spwchg $LOGNAME)

expire_date=$(/opt/perl/bin/perl -le 'print scalar localtime(('$exp_date'))')

if [ $days_left -lt 16 ]
then
echo "\n$LOGNAME expire: $expire_date days_left: $days_left" >> /home/root_mail.txt
continue
fi

mail $LOGNAME < /home/root_mail.txt
echo > /home/root_mail.txt
F Verschuren
Esteemed Contributor

Re: script to mail passwd expire date

there are more than one roads to rome, I think this anser I have got in 2002 is the easyist way to do it:
(asuming hp-ux)
If its any further help - assuming you have a trusted system, the following script will output last changed dates for all users. I can't get the expire date command option exptm to work on my system for as yet unknown reasons but you should be able to work out the expire date from the last changed date.
You should also look at the man pages for getprpw available courtesy of Stephan Farrely's answer here - http://forums.itrc.hp.com/cm/QuestionAnswer/0,,0xebf46c96588ad4118fef0090279cd0
f9,00.html

for USER in $(more /etc/passwd|cut -d":" -f1)
do
DATE=$(/usr/lbin/getprpw -r -m spwchg $USER)
echo "$USER:$DATE"
done
M.Thomas
Frequent Advisor

Re: script to mail passwd expire date

By mistake ,I posted in Tru64 forum
Iam using HPUX
Steven Schweda
Honored Contributor

Re: script to mail passwd expire date

So, perhaps you should close the thread in
the Tru64 forum.

It rarely hurts to include the OS and version
in any question here, and sometimes it helps.