|
Unix script (sh): state of ftp process
Hi guys,
I’m writing a script in which I have to get file from a remote host by ftp. The problem is that the remote machine could be very slow, not connected or ok. To resolve this problem, I write this:
[……]
echo "verbose on" > ftprap.cmd
echo "prompt " >> ftprap.cmd
echo "ascii" >> ftprap.cmd
echo "passive off" >> ftprap.cmd
echo "mget * " >> ftprap.cmd
echo "quit" >> ftprap.cmd
ftp %IP < ./ftprap.cmd > ftp.log 2>&1 &
PID_FTP=`echo $!`
sleep 60
ps -o pid,tty,time,cmd,state|grep -E "$PID_FTP%S" >/dev/null 2>/dev/null
if [ $? = 0 ]
then
kill -9 $PID_FTP >> ftp.log 2>&1
fi
[……]
To kill ftp only if it is blocked.
It happens that even if ftp runs, ps shows me with state = S, that is sleeping!!! I try to run the script with “sleep 1”, while it’s transferring a lot of file, and I’m sure of this: ps shows ftp is sleeping and then the script kills it.
I’m not so very expert about unix scripting, so I don’t’ know where I make mistakes.
Would you help me? Thanks in advanced.
|