SUMMARY: Short Version Output Redirection Query

From: James Coby <james.coby_at_veritas.com>
Date: Fri Apr 27 2001 - 11:19:22 EDT
Furnished by:

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@veritas.com
  > Phone 651-604-3066
  > After Hours:
  > Please contact VERITAS Support at the
  > following number.
  > 1-800-342-0652
  >_______________________________________________
  >sunmanagers mailing list
  >sunmanagers@sunmanagers.org
  >http://www.sunmanagers.org/mailman/listinfo/sunmanagers
  >
--------------------------------------------
 James.Coby@veritas.com
 Phone 651-604-3066
 After Hours:
 Please contact VERITAS Support at the
 following number.
 1-800-342-0652
Received on Fri Apr 27 16:19:22 2001

This archive was generated by hypermail 2.1.8 : Wed Mar 23 2016 - 16:24:53 EDT