Show Password



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 Display Modes
Old 02-12-2018
leecopper leecopper is offline
Registered User
Join Date: May 2017
Last Activity: 19 February 2018, 10:19 PM EST
Posts: 13
Thanks: 6
Thanked 0 Times in 0 Posts
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
Old 02-12-2018
rbatte1 rbatte1 is offline Forum Staff  
Root armed
Join Date: Jun 2007
Last Activity: 16 July 2018, 10:44 AM EDT
Location: Lancashire, UK
Posts: 3,584
Thanks: 1,592
Thanked 706 Times in 633 Posts
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,
Sponsored Links
Old 03-15-2018
kah00na's Unix or Linux Image
kah00na kah00na is offline
Registered User
Join Date: Jul 2007
Last Activity: 15 March 2018, 11:37 AM EDT
Location: Kansas
Posts: 300
Thanks: 21
Thanked 28 Times in 21 Posts
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..
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 02:29 PM.

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