capturing a return code
am 12.11.2007 12:39:11 von droid
I have a conundrum best explained by the following items:
Cut from "man ncftpget":
DIAGNOSTICS
ncftpget returns the following exit values:
0 Success.
-------------------------------=<(*)>=--------------------------------
Snippet from "bak_website" script:
echo "bak_website: Now archiving http://mywebsite.com"
ncftpget -RV -u user -p passwd ftp://mywebsite.com .
# move and list the archived files
val=$?
if [ $val -eq 0 ]; then
mvarc
# moves files from dir n to dir n+1
else
echo "bak_website failed"
fi
-------------------------------=<(*)>=--------------------------------
Message 44:
From droid@opus.ynet Mon Nov 12 04:17:56 2007
X-Original-To: droid
Delivered-To: droid@opus.ynet
From: droid@opus.ynet
To: droid@opus.ynet
Subject: Cron /usr/local/bin/bak_website
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
Date: Mon, 12 Nov 2007 04:00:02 -0500 (EST)
bak_website: Now archiving http://mywebsite.com
ncftpget: server said: File successfully transferred
bak_website failed
-------------------------------=<(*)>=--------------------------------
On inspection I find the file was successfully transferred but mvarc
never executes. Shouldn't the message from the remote server set a
return code of zero? How can I capture ncftpget's return code?
droid
--
Whom computers would destroy, they must first drive mad.
Re: capturing a return code
am 12.11.2007 15:12:48 von Bill Marcum
On 2007-11-12, Jim Showalter wrote:
> I have a conundrum best explained by the following items:
>
> Cut from "man ncftpget":
>
> DIAGNOSTICS
> ncftpget returns the following exit values:
>
> 0 Success.
>
> -------------------------------=<(*)>=--------------------------------
>
> Snippet from "bak_website" script:
>
> echo "bak_website: Now archiving http://mywebsite.com"
> ncftpget -RV -u user -p passwd ftp://mywebsite.com .
>
> # move and list the archived files
> val=$?
> if [ $val -eq 0 ]; then
> mvarc
> # moves files from dir n to dir n+1
> else
> echo "bak_website failed"
> fi
>
> -------------------------------=<(*)>=--------------------------------
>
> Message 44:
> From droid@opus.ynet Mon Nov 12 04:17:56 2007
> X-Original-To: droid
> Delivered-To: droid@opus.ynet
> From: droid@opus.ynet
> To: droid@opus.ynet
> Subject: Cron /usr/local/bin/bak_website
> X-Cron-Env:
> X-Cron-Env:
> X-Cron-Env:
> X-Cron-Env:
> X-Cron-Env:
> Date: Mon, 12 Nov 2007 04:00:02 -0500 (EST)
>
> bak_website: Now archiving http://mywebsite.com
> ncftpget: server said: File successfully transferred
> bak_website failed
>
> -------------------------------=<(*)>=--------------------------------
>
> On inspection I find the file was successfully transferred but mvarc
> never executes. Shouldn't the message from the remote server set a
> return code of zero? How can I capture ncftpget's return code?
>
val=$?
echo "return code=$val"
You might try adding the -d option to ncftpget. It could be that one or
more files were transferred successfully but some were not, or the ftp
server is not a Unix server.
Re: capturing a return code
am 13.11.2007 08:26:34 von droid
On Nov 12, 9:12 am, Bill Marcum wrote:
>
> val=$?
> echo "return code=$val"
>
> You might try adding the -d option to ncftpget. It could be that one or
> more files were transferred successfully but some were not, or the ftp
> server is not a Unix server.
Good idea, Bill. I will try that tonight and post findings here.
There must
be some problem files causing an error return, because the server is
Unix.
Re: capturing a return code
am 13.11.2007 12:13:23 von droid
> On Nov 12, 9:12 am, Bill Marcum wrote:
>
>
>
> > val=$?
> > echo "return code=$val"
>
> > You might try adding the -d option to ncftpget. It could be that one or
> > more files were transferred successfully but some were not, or the ftp
> > server is not a Unix server.
Good suggestions, Bill. I added "echo "return code=$val"" and used "-
d ncftpget.log". The server is Linux, so that is not the problem.
The latest cron message has:
bak_website: Now archiving http://mywebsite.com
ncftpget: server said: File successfully transferred
return code=3
bak_website failed
The ncftpget.log file is 805954 bytes - ncftpget does a lot of
business! But grepping it for "error", "fail" and "warn" returns
nothing.
Could return code 3 be set by the server message, "File successfully
transferred" instead of by ncftpget?
Re: capturing a return code
am 13.11.2007 21:02:53 von Bill Marcum
On 2007-11-13, droid wrote:
>> On Nov 12, 9:12 am, Bill Marcum wrote:
>>
>>
>>
>> > val=$?
>> > echo "return code=$val"
>>
>> > You might try adding the -d option to ncftpget. It could be that one or
>> > more files were transferred successfully but some were not, or the ftp
>> > server is not a Unix server.
>
> Good suggestions, Bill. I added "echo "return code=$val"" and used "-
> d ncftpget.log". The server is Linux, so that is not the problem.
> The latest cron message has:
>
> bak_website: Now archiving http://mywebsite.com
> ncftpget: server said: File successfully transferred
> return code=3
> bak_website failed
>
> The ncftpget.log file is 805954 bytes - ncftpget does a lot of
> business! But grepping it for "error", "fail" and "warn" returns
> nothing.
>
Could you post a sample of that file, maybe the first or last 20
lines?
> Could return code 3 be set by the server message, "File successfully
> transferred" instead of by ncftpget?
>
That should not happen. Maybe you could try changing http:// to ftp://.
Have you tried getting files manually one at a time to see if you get an
error? Or you might try a loop like this:
until ncftpget -R http://mywebsite.com; do sleep 60; done
By default, ncftpget should try to resume a failed transfer, but this
might be a waste of time if the transfer failed for reasons other than
a broken connection (e.g. permission problems, i/o errors or disk full).
Re: capturing a return code
am 13.11.2007 23:08:05 von droid
On Nov 13, 3:02 pm, Bill Marcum wrote:::
>
> Could you post a sample of that file, maybe the first or last 20
> lines?
Output of "tail -n 20 ncftpget.log"
Cmd: MDTM stats/index.html
213: 20071112130935
Cmd: PASV
227: Entering Passive Mode (208,109,181,123,187,244)
Cmd: RETR stats/index.html
150: Accepted data connection
226: File successfully transferred
0.000 seconds (measured here), 15.92 Mbytes per second
Cmd: MDTM stats/navfile.html
213: 20071112130935
Cmd: PASV
227: Entering Passive Mode (208,109,181,123,250,77)
Cmd: RETR stats/navfile.html
150: Accepted data connection
4.1 kbytes to download
226: File successfully transferred
0.000 seconds (measured here), 118.22 Mbytes per second
Cmd: QUIT
221: Goodbye. You uploaded 0 and downloaded 18481 kbytes.
Logout.
>
> > Could return code 3 be set by the server message, "File successfully
> > transferred" instead of by ncftpget?
>
> That should not happen. Maybe you could try changing http:// to ftp://.
The ncftpget command line does access "ftp://mywebsite.com" (see my
first post). The "http://" thing is just the echo line.
>
> Have you tried getting files manually one at a time to see if you get an error?
I've used get from plain ftp and also mirrored the entire site using
wget. Or did you mean: use ncftpget to get files one-at-a-time?
>
> Or you might try a loop like this: until ncftpget -Rhttp://mywebsite.com;do sleep 60; done
>
> By default, ncftpget should try to resume a failed transfer, but this
> might be a waste of time if the transfer failed for reasons other than
> a broken connection (e.g. permission problems, i/o errors or disk full).
You really think it's an error then? I'm not sure. I get consistent
results every run, the total bytes downloaded increase just a little
each day, as you would expect. Also, the total bytes are just
slightly less than what I get with wget, which makes sense because
wget adds a ".listing" file to each directory.
But I'm not familiar with any of this stuff so I really appreciate
your help. If you want the entire ncftp.log, I could email it to you.