LinuxQuestions.org
Help answer threads with 0 replies.
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 09-01-2008, 03:36 AM   #1
evansd321
LQ Newbie
 
Registered: Aug 2008
Posts: 24

Rep: Reputation: 0
Cool How can i sort the "w" output by IDLE time?


Hi all,

I have 100's of sessions on my Linux server and I want to kill off sessions that have been IDLE for a long time.

I can see the IDLE time of the sessions by using the w command, but I wanted to know if there was a way I can sort the output of the w command by IDLE time, starting with the highest IDLE time going down to the lowest?

Any help would be MUCH appreciated
 
Old 09-01-2008, 03:40 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Code:
w |sort -n -k 5
 
Old 09-01-2008, 03:58 AM   #3
evansd321
LQ Newbie
 
Registered: Aug 2008
Posts: 24

Original Poster
Rep: Reputation: 0
Perfect!!

Thanks for that matthewg42, that was driving me CRAZY!!

 
Old 09-01-2008, 07:23 AM   #4
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,300

Rep: Reputation: 102Reputation: 102
Smile

See this you might find it useful.

=>Print users who are idle for more than 15 mins
Code:
who -u | sed -e "s/\./0/" -e "s/://g" | awk '$6 > 15' | awk '{print $7}'
=>Kill the above users.
kill -9 `who -u | sed -e "s/\./0/" -e "s/://g" | awk '$6 > 15' | awk '{print $7}'`


Add below code /etc/bashrc
Code:
--------------------------------------------------------
export TMOUT=300
case `tty | cut -d "/" -f 3` in
   tty1|tty2|tty3|tty4|tty5|tty6 ) export TMOUT=300;;
esac
--------------------------------------------------------
So that shell sessions on the consoles 1-6 are logged out after 5 mins idle time, but those running withing a GUI session such as Gnome or KDE or over an ssh connection are not affected.




Hope this helps.
 
Old 09-10-2008, 03:40 AM   #5
evansd321
LQ Newbie
 
Registered: Aug 2008
Posts: 24

Original Poster
Rep: Reputation: 0
Talking Brilliant

Hey vikas027,

Sorry for the late reply, I have been away, but thanks for your suggestion, it works perfect.

Darren
 
  


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
Reading an application's output in "real time" simopal6 Linux - Software 7 11-22-2014 05:54 AM
LFS6.3 - Ch5.4.1 "/bin/sh sort not found" error at "make bootstrap" ubyt3m3 Linux From Scratch 2 06-23-2008 12:09 AM
Feeding the output of "diff" or "cat" command to dpkg --purge kushalkoolwal Debian 9 06-19-2008 07:27 AM
usb hdd "device not ready" on write after short idle time human_blip Linux - Hardware 7 10-13-2006 02:31 AM
Gaim idle time reporting: "x usage" option disappeared DiscoStoo Linux - Software 2 12-23-2004 02:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:47 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration