LinuxQuestions.org
Register a domain and help support LQ
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, 01: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, 01:42 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
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, 01: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, 01:11 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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, 12:08 PM   #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


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 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 11:22 AM
how to kill the process after specific time? samengr Linux - General 5 02-17-2010 12:19 PM
bash `kill`: process 'B' silently dies; but process 'A' = `kill` spews back debris! GrapefruiTgirl Programming 9 06-23-2009 10:42 AM
Shell Script : Kill a running process when another process starts ashmew2 Linux - General 3 08-20-2008 04:47 AM
kill the process invoked from a shell script, when the script is killed kskkumar Linux - Software 8 05-23-2007 12:29 PM


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