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!

To find the pid for a FTP process 2

Status
Not open for further replies.

crystal28

Programmer
Oct 23, 2002
108
US
I have a script in which i FTP files and every time the FTP is complete i need to kill it.How do i find the Process id for the FTP's in the script.If it was a whole file being executed once i do know how to do this,but in this case they are multiple processes in a single shell script
 
lst1=`ps -e | grep ftp| grep -v grep | grep -v ftpd| awk '{print $1}'`
# Add more lines here if you want to search and kill other procs
# eg
# lst2=`ps -e| grep msg......
# lst3=`ps -e| grep other....

lst=$lst1' '$lst2' '$lst3' '$lst4
for prcid in $lst
do kill $prcid
done

Regards --
| Mike Nixon
| Unix Admin
| ----------------------------
 
I can't really give you a true answer to this without more info. I'm a little confused as to why you have a ftp script that does not exit on completion or at least return to the calling script to continue processing.

....but if you really want to kill off YOUR ftp's then you need to tweak mikes code a little

ps -fu <YOURID>|grep ftp|grep -v grep|nawk '{print $2}'|while read pid
do
kill $pid
done

Give us a bit more info and I'm sure we can come up with a better solution!

Adam
 
Thank you so much Adam for ur reply i really appreciate that.The FTP process takes so long and just does not exit after completion.This whole script is to be executed every 15 mins and i have a crontab for that already but it has to be killed inside the script so that it just exits after FTPing.

 
how long will take before people re-read 'ps' man pages ?
and realize (the correct statement)
ps -ef|grep ...|grep -v grep| awk OR cut OR sed OR what_you_want
is nowaday at least obsolete ??
why not use the NEW options of (sys5)ps ??
NOTE the space after * in sed cmd
#!/bin/sh
WHAT_YOU_SEARCH=aaa
pid=`/bin/ps -efocomm,pid|sed -ne &quot;s/.*$WHAT_YOU_SEARCH.* //p&quot;`
[ x$pid = x ] && exit
kill 0 $pid || exit
kill -9 $pid
-----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
You can search by portnumber on linux:

netstat -pantu | grep :21

Hope this helps.
 
Thanks Adam,Mike,w1nn3r,jamisar.I appreciate your help.The FTP takes too long to execute cause it has to delete the temp directories after it has FTPd the files and also the reason it does not get killed is what i am working on right now.
I used a foreach loop and am killing it right now i am also going to try bye at the end of all the processes.Yes i am getting older..I will be 29 soon..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top