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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass PID to kill using script

Status
Not open for further replies.

hcclnoodles

IS-IT--Management
Jun 3, 2004
123
GB
Hi there, i wonder if anyone can help

is there any way that i can write a script that will kill all current ftp processes, for example if ps -ef | grep ftp produces 3 active proceses, then I would like to somehow extract the PID for each one and pass that to kill -9

has anybody done this before that could give me some ideas


cheers
 
Something like this ?
for sig in 15 9; do
pids=$(ps -e | awk '$NF=="ftp"{printf "%d ",$1}')
[ "$pids" ] && kill -$sig $pids && sleep 2
done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I'd be interested to know why you want to kill all current ftp processes - aren't they doing something?
 
You could try this one.

#!/bin/sh
# find process ... kill it.
ftppid=0
ftppid=`/usr/bin/ps -ef | /usr/bin/grep ftpproc| /usr/bin/grep -v grep | /usr/bin/cut -c9-14`
if [ "$ftppid" = "" ]; then
echo could not find ftp processes
else
echo $ndmpid
/usr/bin/kill -HUP $ftppid
fi


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top