Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate user's last login to check if > 90 days 1

Status
Not open for further replies.

pdtak

Technical User
Feb 25, 2008
63
US
I need a script to figure out if a user's last login was 90 days or older. OS=AIX, shell=Korn
Here's what I have so far:
====
#!/usr/bin/ksh
NOW=`lsuser -a time_last_login root | awk -F= '{ print $2 }'`
(( LAST_LOGIN_TIME = 0 ))
(( DIFF = $NOW - $LAST_LOGIN_TIME ))
lsuser -a time_last_login ALL |\
while read LAST_LOGIN_RECORD
do
(( DIFF = NOW - LAST_LOGIN_TIME ))
if [[ $LAST_LOGIN_TIME <= 0 ]]; then
echo "LAST_LOGIN_TIME <= 0"
else
echo "FOUND! LAST_LOGIN_TIME > 0"
fi
done
====
Thanks in advance!
 
What is a typical output of your lsuser -a time_last_login command ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Here's a sample output from "lsuser -a time_last_login ALL"
user1
user2
user3
user4 time_last_login=1196269598
user5 time_last_login=1225408924
user6
user7 time_last_login=1225067772
user8
user9

the time is "seconds after 1/1/1970", ie. for root:
root time_last_login=1225458046 which is equal to 10/31/2008 09:20AM

Thanks.
 
a starting point:
Code:
#!/usr/bin/ksh 
NOW=$(lsuser -a time_last_login root | awk -F= '{print $2}')
lsuser -a time_last_login ALL | awk -F= 'NF==2 && $2<=('$NOW'-90*24*3600)'


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV!
That's what I needed to get going on this script.
You're the best!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top