hi ecasadella, below is the script which i'm trying to do.. this script runs every 15 minutes and ftp's to a site to get files... sometimes the ftp session hangs up.. so before invoking this script next time i've to chek whether the previous ftp is still running or not.. if running i've to kill that ftp and start a new one... thanks for your help all the way from y'day...
#!/bin/csh
if ( -f ./myftppid ) then
set oldpid = `cat ./myftppid`
ps -p $oldpid | egrep "ftp" ; set stat = $status
echo $oldpid
while ( $stat == 0 )
# Last invocation of the script still running....
@ x ++
if ( $x == 10 ) then
# tried 10 times to kill it and it wouldn't die
echo "Couldn't kill old process"
echo " "
exit 5
endif
echo "Old FTP still running "
kill -9 $oldpid
sleep 1
ps -p $oldpid | egrep "ftp" ; set stat = $status
end
endif
# put the PID in a file so we can check it next time we start
#echo $$ >! ./myftppid
echo !ps | egrep "ftp" | awk '{print $1}' > ./myftppid
echo ftp -inv \<\< ! > ./tmp5
echo open
>> ./tmp5
echo user uname pwd >> ./tmp5
echo cd /temp/temp1 >> ./tmp5
echo get file1 >> ./tmp5
echo quit >> ./tmp5
chmod 744 ./tmp5
./tmp5 > ./tmp66
# remove the PID file if the script complete correctly.
rm -f ./myftppid