LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-13-2008, 10:10 AM   #1
cizzi
Member
 
Registered: Jun 2001
Distribution: Gentoo
Posts: 153

Rep: Reputation: 19
How to find innactive users?


I'm looking for a way to find users who have no logged in the system for 90 days so I can delete or warn them afterwards. Is there a linux command that can do this for me or do I have to write some kind of bash script?
 
Old 04-13-2008, 12:11 PM   #2
tiocsti
LQ Newbie
 
Registered: Apr 2008
Location: Atlanta, GA
Distribution: [linux] Ubuntu, [bsd] FreeBSD, NetBSD
Posts: 21

Rep: Reputation: 15
Quote:
Originally Posted by cizzi View Post
I'm looking for a way to find users who have no logged in the system for 90 days so I can delete or warn them afterwards. Is there a linux command that can do this for me or do I have to write some kind of bash script?
lastlog -b 90


This will get users who never logged in as well, in addition to system users. The former problem can be solved with a grep -vi 'never logged in' though.

Last edited by tiocsti; 04-13-2008 at 12:13 PM.
 
Old 04-13-2008, 12:28 PM   #3
cizzi
Member
 
Registered: Jun 2001
Distribution: Gentoo
Posts: 153

Original Poster
Rep: Reputation: 19
Thanks, thats exactly what I needed!
 
Old 04-20-2008, 09:14 AM   #4
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
I just ran lastlog -b 90, & was a bit disappointed when the list was so filled w/ system/daemon user names that I couldn't easily find the one human that hadn't ever logged in.

I checked the man page & the format of /var/log/lastlog, but I don't see any way, even the possibility of any way, to easily filter on UID or other criteria.

I envision a too complicated script that has to parse the UID's from /etc/passwd in the middle of processing the output from lastlog. I think the approach I am imagining is wrong.

Does anyone know an eas[y|ier] way of doing this?
 
Old 04-20-2008, 07:20 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Code:
awk -F: '$3 < 500 {print $1}' /etc/passwd > list
last | grep -v -f list
< 500 is true on *my* machine, may be a < 1000 on yours?



Cheers,
Tink

Last edited by Tinkster; 04-20-2008 at 07:30 PM.
 
Old 04-21-2008, 06:20 AM   #6
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Nice. Not quite as simple as I was hoping for, it's 2 lines ; but way less Byzantine than the calling awk w/in awk than I was envisioning.

BTW, the last time I used grep -f, grep -Ff worked much faster. It was a long list & a recursive grep, & -F made a huge difference. This is not so large a problem; so, while there is a measurable difference, it is not noticeable:
Code:
$ awk -F: '$3 < 1000 {print $1}' /etc/passwd > users_list

$ time lastlog -b 90 | grep -vf users_list
Username         Port     From             Latest
onthego                                    **Never logged in**
avg                                        **Never logged in**

real    0m0.061s
user    0m0.052s
sys     0m0.004s

$ time lastlog -b 90 | grep -vFf users_list
Username         Port     From             Latest
onthego                                    **Never logged in**
avg                                        **Never logged in**

real    0m0.012s
user    0m0.004s
sys     0m0.004s
Thanks for the code, I did find a user I didn't notice except for the filtering.
 
Old 05-26-2008, 10:24 AM   #7
filex
Member
 
Registered: Sep 2004
Posts: 56

Rep: Reputation: 15
what is the different between last and lastlog?I did a test and found last & lastlog command have different result.
 
Old 05-27-2008, 07:17 AM   #8
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Are you asking about differences more subtle than those described in the respective man pages?
 
Old 05-27-2008, 11:24 AM   #9
filex
Member
 
Registered: Sep 2004
Posts: 56

Rep: Reputation: 15
Said a username: test1 last login date is 1 Jan 2008.

The 'last' command do not show username: test1 but the 'lastlog' command show me test1 results.
 
Old 05-28-2008, 06:25 AM   #10
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Did you bother to read the man pages, as I tried to politely suggest in my post #8?

In short, they are different commands, why do you expect them to be the same/behave the same way?
Or am I missing the point of your Q entirely?
 
  


Reply

Tags
lastlog



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I find connected users? adham1sa Linux - Networking 6 09-11-2009 03:44 PM
Find Users in Network ashishag Linux - Networking 1 12-16-2006 08:02 AM
find out which users are connected??? lemay_jeff Linux - Newbie 2 06-15-2004 10:14 AM
Find Users by area??? datadriven LQ Suggestions & Feedback 7 04-24-2004 07:28 AM
How do you find ip address of users? Alinuxnoob Linux - Security 6 02-28-2002 08:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration