Script to calculate user's last login to check if > 90 days


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to calculate user's last login to check if > 90 days
# 1  
Old 10-31-2008
Script to calculate user's last login to check if > 90 days

I need a script to figure out if a user's last login was 90 days or older. OS=AIX 5.3, 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!
# 2  
Old 10-31-2008
Hammer & Screwdriver Just thinking this through

Code:
> last | grep xxx | head -1
xxx   sshd         10-1-111-111-bos Thu Oct 30 11:12 - 11:12  (00:00)
>

That told me my last login was yesterday at 11:12 am
So, if that gets you started, then review date calculations.
See the following:
https://www.unix.com/unix-dummies-que...html#post16559
# 3  
Old 10-31-2008
For AIX you might want to try lssec:
lssec -f /etc/security/lastlog -s root -a time_last_login

You will have to convert it to a readable date.
# 4  
Old 11-01-2008
Date calculations

Quote:
Hi all, I couldn't help thinking that using that Perderabo script You linked to is way over the top for a simple problem like determining wheher 90-days has passed or not. Actually for any dates after 1970, one should use the date program. One way is to express the date in seconds since 1970-01-01 00:00:00 UTC.

Code:
echo $((($(date +%s)-$(date +%s -d 2001-10-21))/86400))

This is eqivalent to "Todays date expressed in seconds, minus the older date, expressed in seconds, and divide the difference by 86400, the number of seconds per day," resulting in the difference in days between the dates. This vaild for any dates after 1970-01-01 up until, well, raher a way up in the future. The date string must for simplicity be expressed in Your current LOCALE.

Now handling dates before 1970, that is a different story!

/Lakris

Last edited by Lakris; 11-01-2008 at 06:38 AM.. Reason: LOCALE considerations
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Last user login more than certain days

Hi guys , I would like to check if there is any command I can list the inactive user with not log in more than 50 days? Any help will be appreciated. Thanks (2 Replies)
Discussion started by: leecopper
2 Replies

2. Shell Programming and Scripting

Calculate the number of days between 2 dates - bash script

I wrote the day calculator also in bash. I would like to now, that is it good so? #!/bin/bash datum1=`date -d "1991/1/1" "+%s"` datum2=`date "+%s"` diff=$(($datum2-$datum1)) days=$(($diff/(60*60*24))) echo $days Thanks in advance for your help! (3 Replies)
Discussion started by: kovacsakos
3 Replies

3. Shell Programming and Scripting

How to Login as another user through Shell script from current user[Not Root]

Hi Every body, I would need a shell script program to login as different user and perform some copy commands in the script. example: Supppose ora_toms is the active user ora_toms should be able to run a script where user: ftptomsp pass: XXX should login through and run the commands ... (9 Replies)
Discussion started by: ujjwal27
9 Replies

4. Shell Programming and Scripting

KSH script Not working (calculate days since 1/1/2000 given day 4444)

I am unable to get this KSH script to work. Can someone help. I've been told this should work with KSH93. Which I think I have on Solaris 10. If I do a grep -i version /usr/dt/bin/dtksh I get @(#)Version M-12/28/93d @(#)Version 12/28/93 @(#)Version M-12/28/93 This is correct for... (5 Replies)
Discussion started by: thibodc
5 Replies

5. Web Development

Calculate the number of days between 2 dates - PHP

Is this code good for this purpose? <?php $date1 = mktime(0,0,0,01,01,1991); $date2 = mktime(0,0,0,03,22,2012); $diff = $date2 - $date1; $days = $diff / (60*60*24); echo ($days . "<br />"); ?> (3 Replies)
Discussion started by: kovacsakos
3 Replies

6. Shell Programming and Scripting

Calculate days between yyyyMmmdd dates on Solaris

I extract dates from the log file and need to calculate days between two dates. My dates are in yyyyMmmdd format. Example: $d1=2011 Oct 21 $d2=2012 Feb 20 I need to calculate the number of days between $d2 and $d1. This is on Solaris. Any ideas? Thanks, djanu (4 Replies)
Discussion started by: djanu
4 Replies

7. Shell Programming and Scripting

Calculate N days from a file output

OK, here is the output from a cron I have here: FULL OUTPUT: acoxxx Lastlogin= 2010/07/15 13:10 db2t Lastlogin= 2010/07/16 13:09 db2tadm Lastlogin= 2010/07/20 13:09 eisuser Lastlogin= 2010/07/20 11:53 israel Lastlogin= 2010/07/10 11:42 nmon Lastlogin= 2010/07/05 12:55 norbac Lastlogin=... (4 Replies)
Discussion started by: iga3725
4 Replies

8. Shell Programming and Scripting

Calculate 30/31 days from today date script

Hi Guys, I was working some time ago n was in need to calculate date 30/31 days from today including Feb (Leap yr stuff). Today date is variable depending on day of execution of script. I tried searching but was not able to get exactly what I needed....So at that I time I implemented by my own... (3 Replies)
Discussion started by: coolgoose85
3 Replies

9. Shell Programming and Scripting

calculate the number of days left in a month

does any one have any ideas how i would go about calculating the number of days left in the month from a bash script ?. I want to do some operations on a csv file according to the result (8 Replies)
Discussion started by: dunryc
8 Replies

10. Solaris

How to check the last login user were doing in the system

Hi, I'm new to solaris/ Unix and would like to know how to check in the system what was the last login user were doing. Is there any way to check this? Thanks in advanced. (1 Reply)
Discussion started by: raziayub
1 Replies
Login or Register to Ask a Question