LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   help w/ script to kill process(es) based on time they've been running. (https://www.linuxquestions.org/questions/linux-newbie-8/help-w-script-to-kill-process-es-based-on-time-theyve-been-running-848204/)

jcardoza 12-03-2010 12:30 PM

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

GrapefruiTgirl 12-03-2010 12:42 PM

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.

jcardoza 12-08-2010 12:04 PM

Does anyone have any idea how to complete this?

chrism01 12-09-2010 12:11 AM

Code:

time=$(ps -ef|grep pname|awk '{print $7}')
note that the value returned is the cpu time used, not the elapsed time.

jcardoza 12-09-2010 11:08 AM

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.


All times are GMT -5. The time now is 03:14 AM.