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
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.
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
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)
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)
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)
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)
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)
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)
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)
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)
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)