Home Man
Today's Posts

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

Thread Tools Search this Thread
# 1  
Old 02-12-2018
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  
Old 02-12-2018
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:-
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,
# 3  
Old 03-15-2018
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:

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

# /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:
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))" )

The result will look similar to this:
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..
👤 Login to reply

« Previous Thread | Next Thread »
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
Login into another user from user inside script rammm Shell Programming and Scripting 4 09-07-2012 04:04 AM
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
Trying to filter user procs older than n days delphys Shell Programming and Scripting 2 01-18-2012 10:53 PM
error message rmclomv ... SC Login Failure for user Please login: lifegeek Solaris 1 10-21-2009 12:03 PM
How many time have user logged last X days? Kimmo_ UNIX for Dummies Questions & Answers 2 03-20-2009 12:09 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
Delete user file(s) older then 'X' days ?? varungupta UNIX for Advanced & Expert Users 2 08-24-2007 05:01 AM
I create user but i cant login the user i created. jerome UNIX for Dummies Questions & Answers 5 06-09-2006 05:08 PM

All times are GMT -4. The time now is 02:49 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
Show Password