SUMMARY: Short Version Output Redirection Query
2007-12-24 19:49:00
Michael Maciolek
The problem is that 'kill' doesn't read from stdin. The command
line isn't the same as the input stream. You need some other way
to pass your process numbers to the kill command.
There are many ways to do this. Here are four:
1. call a subshell to generate the list of process numbers:
kill -HUP `ps -ef | grep (script name) | awk '{print $2 }'`
2. print the complete 'kill' command for each process, and pass the
resulting commands to a shell for execution:
ps -ef | grep (script name) | awk '{print "kill -HUP " $2 }' | sh
3. use the 'xargs' command which reads from stdin and invokes a named
process using the just-read values as arguments:
ps -ef | grep (script name) | awk '{print $2 }' | xargs kill -HUP
or, if you're running Solaris 7 or newer,
4. there is a new class of programs (pgrep, pkill) that provide the
exact functionality you want:
pkill -HUP "script name"
---------------------------------------------------------------------
On Fri, 27 Apr 2001, James Coby wrote:
>Hello,
>
> There has to be a way to do this unfortunately I can't seem to find it.
>A user has started a group of processes from a script. I can't restart
the
>server
>at present so I thought I'd try this however I can't seem to determine
the
>syntax.
>
>ps -ef |grep ( script name) |awk '{print $2 }' |kill -HUP (output of awk)
>
>I'd like to pass the output of the awk to the kill but cannot determine
what
>the value
>after the -HUP should be represented as.
>I've tried most of the shell variables ie $@ < < - <&2 etc.
>
>Reading the man pages and other references for pipe operations it states
the
>output of the pipe
>is fed to the input of the next command. How do I pass the awk output to
>kill with a
>-HUP.
>
>ps -ef |grep ( script name) |awk '{print $2 }' |kill -HUP
>
>Thanks for the assistance.
>
>Jim
>
>--------------------------------------------
> James.Coby at veritas.com
> Phone 651-604-3066
> After Hours:
> Please contact VERITAS Support at the
> following number.
> 1-800-342-0652
>_______________________________________________
>codeprof mailing list
>codeprof at codeprof.com
>http://www.codeprof.com/execute/ask/?codeinfoid=3340
>
--------------------------------------------
James.Coby at veritas.com
Phone 651-604-3066
After Hours:
Please contact VERITAS Support at the
following number.
1-800-342-0652
Comments
Got something to say?
You must be logged in to post a comment.

