Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

second proccess 1

Status
Not open for further replies.

unixisgood

Technical User
Jan 26, 2005
25
GB
Hi all,
I need a script that will look for some running proccess.Proccess names are have same content as `STARTPROC` but those works for all filesystem ,it will also look that any duplicates of them. STARPROC has to be work only once for every single filesystem.

regarding below proccess list . The script will check that is there any duplicate proccess. For example there are two /a5/script/STARTPROC, it will kill second one which has started after first one. I assume script can catch this from starting time of proccess.


/a1/script/STARTPROC
/a2/script/STARTPROC
/a3/script/STARTPROC
/a4/script/STARTPROC
/a5/script/STARTPROC
/a5/script/STARTPROC
/a6/script/STARTPROC
/a7/script/STARTPROC
/a8/script/STARTPROC
/a9/script/STARTPROC

If is this possible to write a script i will put it into crontab file to run it every 10 minutes.

Thanks for any help.
 
A starting point (typed, untested):
ps -fe | awk '!/STARTPROC/{next}{if($NF in a)system "kill -9 "$2;a[$NF]}'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,
Thanks for answer but it doesn`t work.
Maybe i can check for proccess id. I mean something like if proccess id is greater than first one kill the latest same proccess.
 
Does anyone know how to do this. If no is there also possiblity to have only a warning message to session of root user.

For example from ps output
user8 21049 1 0 00:00:01 ? 0:14 /a8/script/STARTPROC
user7 21049 1 0 00:00:01 ? 0:14 /a7/script/STARTPROC
user8 21049 1 0 00:00:01 ? 0:14 /a8/script/STARTPROC
user9 21049 1 0 00:00:01 ? 0:14 /a9/script/STARTPROC

Warning! "/a8/script/STARTPROC" has duplicate process. Kill it immediately.

Thanks for any help
 
Sorry for the typo:
ps -fe | awk '!/STARTPROC/{next}{if($NF in a)system[!]([/!]"kill -9 "$2[!])[/!];a[$NF]}'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV
Many thanks . It works but not exactly like what i want. It should include also filesystem name to not kill other processes works in different filesystems.

I have tried with puting file system name but got error. So i guess i need to put a syntax to able to add it. Can you help about this please?

ps -fe | awk '!/a8/STARTPROC/{next}{if($NF in a)system("kill -9 "$2);a[$NF]}'
syntax error The source line is 1.
The error context is
>>> !/a8/STARTPROC/{ <<<
awk: Quitting
The source line is 1.
 
$NF include the filesystem, so only duplicates in a filesystem are killed.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top