Multiple hanged FTP processes

Hello people,

I got one problem with a script.

I have a script which runs every five mins and in the script an ftp process is invoked which sends files to a particular location.

The problem is that the ftp process hangs every now and then which causes the whole script to hang.

As the script runs every 5 mins, it invokes an ftp process again and this hanging of ftp process causes the script to be hanged multiple times and in the end a lot of hanged ftp processes and a lot of hanged script processes.

Please someone give me a way so that these ftp process don't get hanged and file transfer is successful without causing the scripts and ftp processes to hang.

Can you show us the script? First we need to check why the ftp query gets stuck. You may want to use -i (disables interactive mode) and -T (sets TTL) switches with the ftp command to avoid getting stuck. But first we need to check the code!

Dear Admin_xor,

Thanks for your response.

following is the ftp part of the script.

#!/bin/sh
PATTERN=`date +%Y%m%d`
USERNAME=xxx
PASSWORD=xxx
IP=x.x.x.x

ftp -inv $IP << END
quote USER $USERNAME
quote PASS $PASSWORD
asc
cd /files/123Files
lcd /records
mput Files*.unl
lcd /records2
mput Files2*.unl
quit
END

As the script runs every 5 mins, I have observed that when the script does not complete and as 5 mins pass, the script is executed again and another ftp process gets started.

How can I stop such thing to happen?

Better use the FLAGGING mechanism, to avoid dupicate trigger of script.

#!/bin/sh
PATTERN=`date +%Y%m%d`
USERNAME=xxx
PASSWORD=xxx
IP=x.x.x.x
 
touch ftpProcessing.lck // When script triggered, will create the lck file
 
ftp -inv $IP << END
quote USER $USERNAME
quote PASS $PASSWORD
asc
cd /files/123Files
lcd /records
mput Files*.unl
lcd /records2
mput Files2*.unl
quit
END
 
rm ftpProcessing.lck // remove once ftp process completed

Also make a change in cron file,

* * * * * ! [ -f ftpProcessing.lck ] && sh <scriptname>

Dear Rksiva,

Thanks for the solution. I will implement and check it.