LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 02-22-2013, 11:34 AM   #1
jdavis_33
LQ Newbie
 
Registered: Dec 2012
Posts: 9

Rep: Reputation: Disabled
Display only logins with an inactivity period of 3 hours or more using who command


My problem is this:

I need to be able to display all logins that have been inactive for more than 3 hours using the who command. How can I accomplish this?

This is what I have so far:

Code:
who -uH | grep -v 0: | pg
This results in a list similar to the one below:

Code:
root       vty1    May  9 10:50    old     14680242
someuser   pts/0   Feb 19 13:45    1:24    31916048   (userpc.domain.net)
someuser2  pts/1   Feb 15 14:43   17:43    45154356   (userpc2.domain.net)
someuser3  pts/11  Feb 20 15:09     .      22347826   (userpc3.domain.net)
someuser4  pts/25  Feb 20 07:42   16:58    30146784   (userpc4.domain.net)
someuser5  pts/34  Feb 22 07:50     .      20381822   (userpc5.domain.net)
With the above command, I see logins and activity under 1 minute; greater than 59 minutes. I only need to see inactivity of 3 hours or more.

Can someone help?
 
Old 02-26-2013, 08:01 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,725
Blog Entries: 54

Rep: Reputation: 2970Reputation: 2970Reputation: 2970Reputation: 2970Reputation: 2970Reputation: 2970Reputation: 2970Reputation: 2970Reputation: 2970Reputation: 2970Reputation: 2970
IMHO the easiest way to do time calculations is to convert time stamps to epoch first. Apart from caveats I don't want to think about like TZ, idle time > 24hrs, idle time > 'date --date="1 year ago";' which source it uses and what should happen on utmp/wtmp rotation/cleanup, time stamps don't show '%Y' and the date format is a human readable '%b %e %H:%M' one. So deal with strings like "old" in the idle time column, convert the start time and idle time to epoch and then check if idle time minus start time equals or is greater than three hours ago. Kludgy, not much fun but doable.
 
Old 02-27-2013, 09:50 AM   #3
fortran
Member
 
Registered: Nov 2011
Location: Cairo, Egypt
Distribution: CentOS, RHEL, Fedora
Posts: 300
Blog Entries: 2

Rep: Reputation: 50
If you could use w command, it can give you better results too.
It shows JCPU & PCPU time based on process used by users. It can give you desired redults too.
But if you want to use who command.
use who -a. it gives you all information about logged in and logged out users.
if exit=0, it means users who are logged out.
You can find the list of logged in users who do not have exit=0

You can use last command for the list of logged in and logged out users.
Here you can find out the users who were logged in more than three hours but currently logged out.
But if you want to see details of logged in users, you can use
Code:
$ last | grep "Feb 27" | grep "still"
It will show the current logged in users of 27 feb with there logged in time.
Suppose it is 20:00 pm and you want to know the users who were logged in around 18:00 pm and all after that, you can use
Code:
 last | grep "Feb 27" | grep "still" | grep -e "18:" -e "19:" -e "20:"
It will show you list of all users who were logged in after 18:00 pm and still logged in.

Last edited by fortran; 02-27-2013 at 10:31 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Screen saver does not start after period of inactivity statguy Slackware 3 02-27-2009 08:52 PM
Blank Screen after short period of inactivity SweetLou Debian 6 12-13-2006 09:45 PM
How do I automatically logout after a period of inactivity? AshleyK Linux - Security 4 12-31-2004 11:47 PM
running a command after a set period of keyboard inactivity? Nocterro Linux - Software 3 09-03-2004 10:04 AM
Log entry during period of inactivity Gavin Linux - General 1 01-14-2002 02:08 AM


All times are GMT -5. The time now is 09:23 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration