[comp.unix.shell] status code from ftp

rolf@sparc1.isgs.uiuc.edu (Rolf Wilson) (02/01/91)

I have a routine to transfer a file to another machine
by ftp. That part works fine. I want to delete the
file that I sent if the transfer worked. That part 
does not.

#!/bin/sh
ftp -n othermachine <<!
user me
put myfile
quit
!
if [ $? -eq 0 ]
then
  rm myfile
fi

The $? return code is always 0, even if the other machine
is never found. Does ftp not return a non-zero code on
failure? Is this not "the last command executed". What
horribly simple thing do I not understand?
  Replies by e-mail, please.

  Thank you very much.

--

Rolf Wilson   Illinois State Geological Survey   rolf@sparc1.isgs.uiuc.edu

calvin@sequent.UUCP (Calvin Goodrich) (02/02/91)

In article <1991Jan31.222142.12395@ux1.cso.uiuc.edu> rolf@sparc1.isgs.uiuc.edu (Rolf Wilson) writes:
>I have a routine to transfer a file to another machine
>by ftp. That part works fine. I want to delete the
>file that I sent if the transfer worked. That part 
>does not.
>
>#!/bin/sh
>ftp -n othermachine <<!
>user me
>put myfile
>quit
>!
>if [ $? -eq 0 ]
>then
>  rm myfile
>fi
>
>The $? return code is always 0, even if the other machine
>is never found. Does ftp not return a non-zero code on
>failure? Is this not "the last command executed". What
>horribly simple thing do I not understand?

i'm not a unix guru by any stretch of the imagination but i do have a pretty
good idea why your script didn't work. ftp will *always* give a return code
of 0 if you *exit* normally from ftp, whether it successfully transferred any
files or not. if something goes wrong and ftp has to exit unexpectedly then
you'll probably get something other than 0. if you want to see if the transfer
worked why not check to see if the file exists with test -f?


have a day, eh.

Calvin Goodrich   / calvin@sequent.sequent.com a\=k)4vk!%t@$+... <EOT> (beep!)

"Scotty, we need that .sig in thirty seconds or we're all dead!"
"Och, Captain! We canna do anathin'! It's still on yir other account!"

(Starfleet. It's not just an adventure, it's a job.)