Question

I am new to UNIX. I want to kill pid of file "File_name" and then I have to run "Recycle_All" script which by default takes the argument 'y'.

#!/bin/ksh
ps -aef | grep "File_name" | awk '{print $2}' | xargs kill -9
/directory>./Recycle y
exit

I am not able to pass 'y' as argument. Also how should I verify that the pids have been killed by the above command.

The error is:

usage: kill [ -signo ] pid ...

./soap_rec.ksh[x]: ./Recycle_All: cannot create
Was it helpful?

Solution

Note: by saying *pid of file "File_name"* i guess that you mean *the pid of process having "File_name" in it's argument list*

First, you should remove the bogus "/directory>" prefix of the last line of script (what did you intend to do with this ?)

And the 1st line should better be written:

  • if you do'nt have "pkill" command:

    ps -aef | awk '/File_name/ && ! /awk/ {system("kill -9 " $2)}' 
    
  • if you have it:

    pkill -9 -f "File_name"
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top