LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 08-06-2007, 01:59 PM   #1
Deviathan
Member
 
Registered: Dec 2005
Posts: 52

Rep: Reputation: 18
Search/destroy old/idle user processes


Hi all,
I need to write a script to keep track of user-created processes on a linux server used for vnc connections. What I want to do is search for processes that are idle for at least a certain amount of time (say 2 weeks) before sending it a kill signal. I am aware of the command "w" and the "ps" command for use in my script. Unfortunately, w doesn't show the pid and ps doesn't give me an idle time. The only other thing was to combine the two results using the TTY number but I haven't really looked at implementing this yet. Are there any other commands or methods that I could use that might be more reliable? thanks for any input!
 
Old 08-06-2007, 02:22 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
keep track of user-created processes on a linux server used for vnc connections
So those processes should (have been) be part of the session ID (SID) aka children of the VNC session? Else, if the users aren't allowed to run stuff in the background, maybe Do Something on X session logout (for instance /etc/X11/gdm/PostSession/*)?
 
Old 08-06-2007, 02:38 PM   #3
ChrisScott
Member
 
Registered: Nov 2006
Location: St Albans, England
Distribution: Fedora c3/5, Suse pro 10/openSuse 10.2, RHES, Zenwalk.....
Posts: 97

Rep: Reputation: 15
Hi,

You could try something like;

Code:
#!/bin/bash

ps -ef > .psef
SIZE=$((`cat .temprocs |wc -l |sed 's?[^0-9]??g'` - 1))
cat .temprocs | tail -$SIZE |awk '{print $2 " since " $5}' | grep -v "[0-9]\{2\}.[0-9]\{2\}" > .temprocs
rm -r .psef
that will give you everything over a day old (at least it does on my SuSE box). Some clever grep/sed/sort-ing could isolate procs started over a week ago. That method won't isolate idle processes though...

Maybe a nightly cron which loops through procs and straces them?

Still automated kills fill me with dread! Personally I'd just look though a 'ps -ef' every couple of days!

Last edited by ChrisScott; 08-06-2007 at 02:39 PM.
 
  


Reply



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
Track idle processes musthafa Linux - Server 1 01-18-2007 07:20 AM
kill idle user ust Linux - Software 3 08-31-2004 02:19 PM
who idle user how to kill saavik Linux - Networking 1 03-04-2004 10:12 AM
Help with file search and destroy script flippy Programming 5 07-25-2003 04:29 PM
5 httpd processes running on an idle box? J_Szucs Linux - Networking 2 04-07-2003 08:58 PM

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

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