Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!sdd.hp.com!zaphod.mps.ohio-state.edu!rpi!dali.cs.montana.edu!milton!uw-beaver!zephyr.ens.tek.com!tektronix!sequent!calvin From: calvin@sequent.UUCP (Calvin Goodrich) Newsgroups: comp.unix.shell Subject: Re: status code from ftp Message-ID: <52090@sequent.UUCP> Date: 1 Feb 91 16:20:27 GMT References: <1991Jan31.222142.12395@ux1.cso.uiuc.edu> Reply-To: calvin@sequent.sequent.com (Calvin Goodrich) Organization: Sequent Computer Systems Lines: 38 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@$+... (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.)