The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
not able to kill find with kill -9 Amardeep UNIX for Dummies Questions & Answers 5 01-04-2007 01:49 PM
KILL PID, intern should kill another PID. rkrgarlapati Shell Programming and Scripting 4 10-17-2006 04:47 AM
how to generate a random list from a given list mskcc Shell Programming and Scripting 3 05-30-2006 12:30 AM
When kill doesnt work, how to kill a process ? VijayHegde UNIX for Advanced & Expert Users 3 05-12-2006 01:24 PM
how to generate a list of files jasongr Shell Programming and Scripting 3 12-13-2005 04:15 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-29-2008
Registered User
 

Join Date: Oct 2007
Posts: 22
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
How to generate a 'kill' list

Hi,

I want to write a script which can generate a kill list for killing process, program name start with f60.., which have been running for more than 8 hours, the list output should looks like:

kill -9 4444176
kill -9 4674520
kill -9 4454180
kill -9 4994523

Can anyone help how to write it?

Thanks!
Victor Cheung
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-29-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,253
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Code:
ps --suitable=options | awk '$7 ~ /^[f]60/ && $5 > 8 { print $1 }' | xargs kill
The "suitable options" and the field numbers to use in the awk script depend on which platform you are on. Consider this pseudo-code.

Are you sure you understand the consequences of "kill -9"? You should use a less drastic signal if at all possible.
Reply With Quote
  #3 (permalink)  
Old 04-29-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,253
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Here's something for Linux.

Code:
ps aux | awk '$11 ~ /(^|\/)[f]60/ { split ($10,t,/:/); if (t[1] > 8) print $2 }'
Reply With Quote
  #4 (permalink)  
Old 04-29-2008
Registered User
 

Join Date: Oct 2007
Posts: 22
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Hi Era,

I use the following in AIX :

ps aux | awk '$11 ~ /(^|\/)f60/ { split ($9,t,/:/); if (t[1] > 8) print $2 }'

and it return:

4468962

and I grep the process:
root@lkmprod11i:/home/oracle/victor> ps -ef|grep 4468962
appl115 4468962 6123696 0 09:05:04 - 0:00 f60runm webfile=5,27368,lkmprod11i_9002_PROD11i
root 9077560 10519380 0 15:15:38 pts/0 0:00 grep 4468962

The program start time is 09:05 and the system current time is 15:15, it is less then 8 hours long, it should not be returned, can you please help and review? Thanks!

On the other hand, I have to add one more condition to it, if the process id or parent process id is 1 then don't let it returned, how to do that?

Thanks!
Victor Cheung

Last edited by victorcheung; 04-30-2008 at 12:12 AM.
Reply With Quote
  #5 (permalink)  
Old 04-30-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,253
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
The PPID is not visible in the ps aux output, you might need different options to get that column also. Then it should be a trivial problem to add '&& $3 > 1' with the correct field number of course before the opening curly.

You want the [f] with the square brackets, otherwise you risk to kill the script itself (in theory, mostly, I guess, in the current scenario; but what if you repurpose the script later? Better make it right).
Reply With Quote
  #6 (permalink)  
Old 04-30-2008
Registered User
 

Join Date: Oct 2007
Posts: 22
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Hi Era,

Sorry, I have edited my post:

I use the following in AIX :

ps aux | awk '$11 ~ /(^|\/)f60/ { split ($9,t,/:/); if (t[1] > 8) print $2 }'

and it return:

4468962

and I grep the process:
root@lkmprod11i:/home/oracle/victor> ps -ef|grep 4468962
appl115 4468962 6123696 0 09:05:04 - 0:00 f60runm webfile=5,27368,lkmprod11i_9002_PROD11i
root 9077560 10519380 0 15:15:38 pts/0 0:00 grep 4468962

The program start time is 09:05 and the system current time is 15:15, it is less then 8 hours long, it should not be returned, can you please help and review? Thanks!


Victor Cheung
Reply With Quote
  #7 (permalink)  
Old 04-30-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,253
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Check man ps for an option which list the actual run time. (Apparently you want wall clock time, not CPU time -- that might not be directly available. Then you need to do some time calculations in awk, which doesn't sounds like much fun.)
Reply With Quote
  #8 (permalink)  
Old 05-02-2008
Registered User
 

Join Date: Oct 2007
Posts: 22
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Thanks Era.
Reply With Quote
  #9 (permalink)  
Old 05-14-2008
Registered User
 

Join Date: Oct 2007
Posts: 22
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Hi Era,

I have the list produced by :

ps -ef -o "user pid ppid cpu etime tty time args"

and the output looks like:

oracle 1626616 1 0 37-05:24:09 - 00:06:29 oracleDEV (LOCAL=NO)
oracle 1638908 1 0 37-05:24:09 - 00:06:24 oracleDEV (LOCAL=NO)
oracle 1642760 1 0 37-05:24:08 - 00:06:23 oracleDEV (LOCAL=NO)
oracle 1651012 1 0 26-01:15:11 - 00:02:07 oracleDEV (LOCAL=NO)
oracle 1655052 1 0 37-05:24:08 - 00:06:22 oracleDEV (LOCAL=NO)
oracle 1659266 1 4 01:14:16 - 00:01:49 oracleDEV (LOCAL=NO)
oracle 1712408 1 0 36-04:08:24 - 00:06:26 oracleDEV (LOCAL=NO)
oracle 1720698 1 0 05:27 - 00:00:00 oracleDEV (LOCAL=NO)
oracle 1728950 1 0 14-06:37:31 - 00:02:33 oracleDEV (LOCAL=NO)
oracle 1732902 1 0 01:52:11 - 00:00:01 oracleDEV (LOCAL=NO)
oracle 1737166 1 0 08:32:27 - 00:00:10 oracleDEV (LOCAL=NO)
oracle 1745166 1 0 08:57:59 - 00:00:18 oracleDEV (LOCAL=NO)
oracle 1753436 1 0 01:24:40 - 00:00:01 oracleDEV (LOCAL=NO)
oracle 1765692 1 0 01:28:10 - 00:00:01 oracleDEV (LOCAL=NO)

The 3rd column is the elapsed time and in Format of [[ dd-]hh:]mm:ss, is it possible I only want it to return the PIDs for processes elapsed longer than 8 hours?

if I issue :
ps -ef -o "user pid ppid cpu etime tty time args" | awk '$8 ~ /(^|\/)[f]60/ && $3>1 { print $2 }'

it returns all the PIDs regardless of elapsed time, can you please advise how to modify the script and let it return only processes elapsed longer than 8 hours?


Many thanks!
Victor Cheung
Reply With Quote
  #10 (permalink)  
Old 05-14-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,253
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
It prints nothing at all for me, the processes are not called f60 and $3 is not greater than 1.

But to focus on the elapsed time, you could say $5 ~ /[0-9]-/ for anything with more than one day (trivially more than 8h then) and for the remaining ones, split($5, t, /:/) and print if t[1] > 8.
Reply With Quote
  #11 (permalink)  
Old 05-14-2008
Registered User
 

Join Date: Oct 2007
Posts: 22
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Thanks Era!
Reply With Quote
Google UNIX.COM
Reply

Tags
linux

Thread Tools
Display Modes


The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
421 service not available, remote server has closed connection ^m automate ftp autosys awk trim bash eval bash exec bash for loop close_wait command copy/move folder in unix couldn't set locale correctly curses.h cut command in unix dead.letter find grep find null character in a unix file grep multiple lines grep or grep recursive inaddr_any inappropriate ioctl for device ksh if logrotate.conf lynx javascript mailx attachment mget mtime ping port remove first character from string in k shell replace space by comma , perl script scp recursive segmentation fault(coredump) sftp script snoop unix stale nfs file handle syn_sent tar exclude test: argument expected unix unix .profile unix forum unix forums unix internals unix interview questions unix mtime unix simulator unix.com vi substitute vi+substitute+end+of+line+character while loop within while loop shell script


All times are GMT -7. The time now is 07:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101