Operating System - HP-UX
1826215 Members
2845 Online
109691 Solutions
New Discussion

Re: calculate the number of days left for password expiry

 
SOLVED
Go to solution
Animesh Chakraborty
Honored Contributor

calculate the number of days left for password expiry

I need to write a script to calculate the number of days left for passwd expiry

To check passwd expiry time :-
root->/usr/lbin/getprpw -m exptm sapr3
exptm=730

last successfull passwd change:-
root->/usr/lbin/getprpw -m spwchg sapr3
spwchg=Thu Jul 4 15:42:02 2002

Current date

# date
Tue Feb 4 20:34:16 SST 2003

days left to to expire passwd =730 - (current date -spwchg date)
Need to convert two dates into numeric value.

Thanks for your time
Animesh

Did you take a backup?
9 REPLIES 9
Pete Randall
Outstanding Contributor

Re: calculate the number of days left for password expiry

Animesh,

What you need is Clay's "date hammer", caljd.sh. See this thread for info (from Clay himself):

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x2b9d4a988422d711abdc0090277a778c,00.html



Pete

Pete
Robert-Jan Goossens
Honored Contributor

Re: calculate the number of days left for password expiry

Hi,

Take a look at next question beleave it will help.

Kind regards,

Robert-Jan.
Robert-Jan Goossens
Honored Contributor

Re: calculate the number of days left for password expiry

Hi,

Take a look at next question beleave it will help.

Kind regards,

Robert-Jan.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x82afba808b46d611abda0090277a778c,00.html
Animesh Chakraborty
Honored Contributor

Re: calculate the number of days left for password expiry

Hi,
I have already tried Clay's perl script
but it is not showing the correct result.
root>perl passwarn.pl ac
ac 4096
cttrg:>passwd -s ac
ac PS 01/22/03 0 60 7
Did you take a backup?
john korterman
Honored Contributor
Solution

Re: calculate the number of days left for password expiry

Hi Animesh,
please try the following script. ATTACHED_SCRIPT must be customised with the path to the attached script and USER set to the user you want to examine.

#!/usr/bin/sh

# Define path to attached script.
#
ATTACHED_SCRIPT=""


# Set the user to examine...
#
USER=""


EXP_DAYS=`/usr/lbin/getprpw -m exptm "$USER"| awk -F= '{print $2}'`


if [ "$EXP_DAYS" = "-1" ]
then
echo $USER does not expire
exit 1
fi

EXP_DAYS_IN_SECS=$(( $EXP_DAYS \* 86400 ))
LAST_CHANGE=`/usr/lbin/getprpw -m spwchg "$USER"| awk -F= '{print $2}'`
# Cut out the various items..
#
L_C_YEAR=`echo $LAST_CHANGE| awk '{print $5}'`
L_C_MONTH=`echo $LAST_CHANGE| awk '{print $2}'`
L_C_DAY=`echo $LAST_CHANGE| awk '{print $3}'`
L_C_HOUR=`echo $LAST_CHANGE| awk '{print $4}'| awk -F: '{print $1}'`
L_C_MINUTE=`echo $LAST_CHANGE| awk '{print $4}'| awk -F: '{print $2}'`
L_C_SECOND=`echo $LAST_CHANGE| awk '{print $4}'| awk -F: '{print $3}'`

# Number of seconds since last change
#
SECS_SINCE_LAST_CHANGE=`$ATTACHED_SCRIPT 1970 $L_C_YEAR $L_C_MONTH $L_C_DAY $L_C
_HOUR $L_C_MINUTE $L_C_SECOND`

# Current date in seconds
#
CURRENT_DATE_SECS=`$ATTACHED_SCRIPT`
# Calculate num. of secs since last change
#
WHEN_SECONDS=$(( $EXP_DAYS_IN_SECS - ( $CURRENT_DATE_SECS - $SECS_SINCE_LAST_CH
ANGE) ))

# Turn seconds into days
#
WHEN_DAYS=$(( $WHEN_SECONDS \/ 86400 ))
echo $WHEN_DAYS




regards,
John K.


it would be nice if you always got a second chance
Rainer von Bongartz
Honored Contributor

Re: calculate the number of days left for password expiry

Animesh

I attached a small C-Program you
should compile with -lsec

The program will go through passwd and print the expiration date and life-time of the password

Regards
Rainer
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Parsadi
New Member

Re: calculate the number of days left for password expiry

Hi Animesh,

How to use this script.
When I run the script I get the following error: Syntax error at line 16 : `&' is not expected.

Richard Ross
Regular Advisor

Re: calculate the number of days left for password expiry

Need to display the expiration/expired status of all users and saw this C program from Rainer .. This needs to run on a 11.0 and 11.11 'Trusted" servers. Seems that fd_expire is always '0'. Has anyone got this to work? or another method to retrieve the values from the system?

Thanks
Richard
Richard Ross
Regular Advisor

Re: calculate the number of days left for password expiry

As a addon .. This is a sample with additional info:

FD_EXPIRE for aydin IS 0
FD_EXPIRE for bhandara IS 0
FD_EXPIRE for rross IS 0

So .. The program is retrieving the info from getprpwent, but finging that fd-expire for ALL users is '0'