AIX

AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

Last user login more than certain days

👤 Login to reply

    #1  
Old 02-12-2018
leecopper leecopper is offline
Registered User
 
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
Sponsored Links
    #2  
Old 02-12-2018
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
If you can use last and get a list of those that have been active for your desired period, then you can use something like:-
Code:
cut -f1 -d ":" /etc/passwd | grep -vf active-list

You have to be careful that the active list doesn't match multiple accounts, e.g. a user named bob in the active list might also match bobby and you won't see it in the output.

How are your users defined? Are there likely to be false-positives in this?

perhaps you also need to merge your active list with a list of service accounts, e.g. root or oracle or whatever. You need to be sure that your listed idle users are checked before you do anything too drastic with them.



I hope that this helps,
Robin
Sponsored Links
    #3  
Old 03-15-2018
kah00na's Unix or Linux Image
kah00na kah00na is offline
Registered User
 
You can get the last login time from the user attributes instead of relying on your last log (we roll ours monthly). This should work but it requires perl to be installed to translate the results into a date and time you can understand:
Code:
user=george

# lsuser -a time_last_login $user |awk '/last_login/{print substr($2,17)}'
1521126318

# /usr/bin/perl -le "print scalar(localtime(1521126318))"
Thu Mar 15 10:05:18 2018

You can read the users from your /etc/passwd file in a loop:
Code:
for user in $(cat /etc/passwd |awk -F':' '{print $1}'); do
LAST=$(lsuser -a time_last_login $user |awk '/last_login/{print substr($2,17)}') && ( printf "$user "; /usr/bin/perl -le "print scalar(localtime($LAST))" )
done

The result will look similar to this:
Quote:
root Thu Mar 15 10:16:48 2018
daemon Thu Mar 15 10:20:01 2018
bin Thu Mar 15 10:20:01 2018
sys Thu Mar 15 10:20:01 2018
adm Thu Mar 15 10:20:01 2018
uucp Thu Mar 15 10:20:01 2018
guest Thu Mar 15 10:20:01 2018
nobody Thu Mar 15 10:20:02 2018
lpd Thu Mar 15 10:20:02 2018
...
Now that I see it, it may not be accurate for system accounts, but it has been working fine for our individual user accounts. You would have to either grep out your user accounts or "egrep -v" your system accounts.

Last edited by kah00na; 03-15-2018 at 11:23 AM..
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
User Account Login Login on your AIX server perl_in_my_shel AIX 1 07-02-2012 05:39 PM
How to Login as another user through Shell script from current user[Not Root] ujjwal27 Shell Programming and Scripting 9 05-27-2012 11:50 AM
error message rmclomv ... SC Login Failure for user Please login: lifegeek Solaris 1 10-21-2009 12:03 PM
Running script from other user rather than login user rawatds Shell Programming and Scripting 3 01-30-2009 12:18 PM
Script to calculate user's last login to check if > 90 days pdtak Shell Programming and Scripting 3 11-01-2008 05:36 AM



All times are GMT -4. The time now is 01:42 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?