LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-03-2010, 12:30 PM   #1
jcardoza
LQ Newbie
 
Registered: Jun 2009
Posts: 23

Rep: Reputation: 0
help w/ script to kill process(es) based on time they've been running.


Is there a way we can have similar script...
I need to identify a process related to how much time have a process running.

Here is an example about the process I need to kill:

UID PID PPID C STIME TTY TIME CMD
cusers1 25037 25035 0 10:28:07 pts/60 0:00 /cms/bin/chipr
cusers1 25041 25037 0 10:28:09 pts/60 0:00 chip
cusers1 25042 1546 0 10:28:09 ? 0:00 win_io_man -t24055 -a1

ps-fu login |grep process
Example:

ps-fu login |grep win_io_man
cusers1 25042 1546 0 10:28:09 ? 0:00 win_io_man -t24055 -a1
then kill 25042

In the example I killed the process by the process name, but I would like to know how much time have the process running before I get this part of the code to kill.

Something like:

check processes:
/cms/bin/chipr
chip
win_io_man

If the process have more than 30 minutes, check the owner and then go:
ps-fu login |grep win_io_man
then kill

Please let me know how to get this script, hope you can help me.
Kind regards
C@RM@N
 
Old 12-03-2010, 12:42 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Hi there,

I have moved your post off of the SOLVED thread you had tacked it onto - in the future, please create your own thread for your question, rather than attaching it on someone else's thread.

Also, please see this link for a quick intro to "code tags" - something you should use when posting pieces of code, or chunks of data files or terminal output, to retain the formatting of the original text.

Finally, here's a link to a recent thread on a similar subject, where there is not yet a solution, but some hints and suggestions have been given for how to proceed with something like this.

Cheers & best regards.
 
Old 12-08-2010, 12:04 PM   #3
jcardoza
LQ Newbie
 
Registered: Jun 2009
Posts: 23

Original Poster
Rep: Reputation: 0
Does anyone have any idea how to complete this?
 
Old 12-09-2010, 12:11 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Code:
time=$(ps -ef|grep pname|awk '{print $7}')
note that the value returned is the cpu time used, not the elapsed time.
 
Old 12-09-2010, 11:08 AM   #5
jcardoza
LQ Newbie
 
Registered: Jun 2009
Posts: 23

Original Poster
Rep: Reputation: 0
I am doing this:

who |egrep username >> test.txt
Then I use:
awk '{ print $5 }' test.txt
Now I have this results:
07:42
10:33
15:01

The hour when the user login into the system.
Then I use date to get the actual time and I am trying an if sentence to eliminate the users that have more than 30 minutes login.

I will send you the script as soon as I have it.
Thanks for your help.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
need script to kill process based on STIME wilmomd Linux - General 5 03-12-2010 10:22 AM
how to kill the process after specific time? samengr Linux - General 5 02-17-2010 11:19 AM
bash `kill`: process 'B' silently dies; but process 'A' = `kill` spews back debris! GrapefruiTgirl Programming 9 06-23-2009 09:42 AM
Shell Script : Kill a running process when another process starts ashmew2 Linux - General 3 08-20-2008 03:47 AM
kill the process invoked from a shell script, when the script is killed kskkumar Linux - Software 8 05-23-2007 11:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:44 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