Operating System - HP-UX
1752567 Members
5144 Online
108788 Solutions
New Discussion юеВ

How to verify FTP Service is running from remote

 
Mohd Ezree
New Member

How to verify FTP Service is running from remote

Hi all,
I've developed a simple scripts automatically to get a file from a remote machine. The configuration is as follows
machine A (UNIX)
machine B (Windows)
The shell script is residing in A, every one minute (cronjob) will execute the shell script in machine A. In machine B we have install an FTP Server to allow the script in machine A to get the file in machine B.
This thing has works fine so far. But lately there is an issue with the network facilities at our client place, there is no connection between machine A and B.
This script will continue to execute because it has been set as a cronjob. This script contain a line to ftp to the FTP server in machine B.
Because the script will hang waiting the response from machine B FTP Server. While the script is hang, the next cronjob comes in to execute the script and again it hangs. Since this script execute every one minutes, an hour it will execute 60 times ,just imagine a day ! This script will hog the server process. In the end the other program is unable to execute their process.
The script is as below
################
echo "open $IP
user $user $pass
ls
bye" | ftp -nvdi
####################

We can check the line is down by using PING, but how to check if the FTP Server service is down in machine B ?



Rgrds
Mohd Ezree
Trial and Error
3 REPLIES 3
Donald Kok
Respected Contributor

Re: How to verify FTP Service is running from remote

Hi Mohd,

I would create a file like ftp_busy in which I would write values like true and false.

At the start of the script, I would check if the value is false. If so, write true in it, and do the rest of the script. If not, exit.

At the end of the script, write false in the script.

This way there will always be just one script running, also in the scenario the ftp connection takes longer than one minute.

Hope this helps
Donald
My systems are 100% Murphy Compliant. Guaranteed!!!
steven Burgess_2
Honored Contributor

Re: How to verify FTP Service is running from remote

Hi

How many ftp sessions do you have running at any one time if there are no problems ? Do you have other open telnet sessions to that server ?

If you only have the one session to that server you could simply , at the start of your script

# Check if current ftp session open

netstat -an | grep

if [ $? != 0 ]
then
echo "open $IP
user $user $pass
ls
bye" | ftp -nvdi
else
echo "ftp session open" > log
exit
fi

HTH

Steve
take your time and think things through
rick jones
Honored Contributor

Re: How to verify FTP Service is running from remote

I would probably change the cron script to a self-submitting "at" job instead.

By making it an "at" job, when it takes however long for the ftp command to time-out and return an error it will naturally preclude the starting of the next script and you will have only one running at a time.

in pseudo-script

do ftpstuff

touch a forward-progress file

at now + one minute scriptname

or something like that
You might then also have a cron job that runs once an hour or whatnot that checks on forward progress on the at jobs so you can get a warning if the script dies a horrible death and stops resubmitting itself.
there is no rest for the wicked yet the virtuous have no pillows