Operating System - HP-UX
1822230 Members
3723 Online
109642 Solutions
New Discussion юеВ

Automatically detecting success or failure of ftp script

 
SOLVED
Go to solution
Dermot Beirne
Frequent Advisor

Automatically detecting success or failure of ftp script

Hi,
I have an ftp process running from a shell script. It is something like this:

{
for host in nemail
do
echo "
open $host
user joe joepass
lcd /archive/dbeirne/admin/testdir1/
ascii
mput p*
close
"
done
} | ftp -i -n

I want to be alerted if the ftp fails for any reason, ie. cannot connected to the host, the username or password is incorrect, etc. I have tried using the standard $? variable, but this shows success even if the ftp fails. Is there a simple way of checking for failures of this type of script, and running a command like sending a page or whatever.

I know that I can grep through it's logfile for errors, but this is cumbersome as it's logfile is being appended to and is quite large, and contains some historic errors.

Thanks in advance.
Dermot.
Happy is harder than money. Anyone who thinks money will make them happy, doesn't have money.
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor

Re: Automatically detecting success or failure of ftp script

Hi Dermot:

I think you're stuck parsing the log of each session. Use the numbers associated with the text of the messages to discern the success or failure of the process. Look at the man pages (1M) for 'ftpd': "Every command produces at least one reply, although there may be more than one. A reply consists of a three-digit number, a space, some text...The number must conform to this standard, but the text can vary...The first digit of the message indicates whether the reply is good, bad, or incomplete."

Set the '-v' [verbose] option with each ftp and redirect stdout & stderr to a file. Parse the messages from the session and look at the at the first digit of the messages. This is the most rigorous approach, I think, to ascertaining the success or failure of a session.

...JRF...
Vincenzo Restuccia
Honored Contributor

Re: Automatically detecting success or failure of ftp script

Insert in shell script if>then>else with exit 0 and exit 1.
Mike Hassell
Respected Contributor
Solution

Re: Automatically detecting success or failure of ftp script

Dermot,

We use something like this:

# Initiate FTP session and transfer files

{
ftp -vin <open hostname
user blah passwd 0
del filename
bin
put $dir/filename filename
EOF
} | grep -e "226 Closing" -e "226 Transfer complete." -e "226 ASCII Transfer com plete."> /dev/null

# Report errors via email

if [ $? -ne 0 ]
then
mailx -s "ftpbatch.sh ftp error to hostname" $MAILLIST > /dev/null
fi

It seems to do the job, but we still have some problems with it. I've actually swapped out this process because it was failing so many times to use ncftp. We have to transfer some files to an offsite NT server and it was hanging way too much, so I opted to use ncftp for it's advanced configuration capabilites:

http://hpux.connect.org.uk/hppd/hpux/Networking/FTP/ncftp-3.0.2/

Hope that helps.

- Mike
The network is the computer, yeah I stole it from Sun, so what?