ftp -i -n -v 2>$ftp_message_file 1>&2 <<EOF

I am trying to understand a ftp script.  Does this mean that the output of 1 is being directed to 2 and does this mean that if no file is retrieve from the FTP session the script ends with status 16?

ftp -i -n -v 2>$ftp_message_file 1>&2 <<EOF
open $NODE
user $USER $PASS
cd $DIRECTORY
binary
get $FILE $FILE
del $FILE $FILE
bye
EOF
}
#
BASENAME=`basename $0`
if [ $# -ne 2 ]
then
    echo "$BASENAME: usage $BASENAME <file_to_transfer> <directory>"
    echo
    echo "$BASENAME called with invalid number of parameters"
    echo "Processing Abnormally Terminated"
    exit 16
fi


Thanks for the assistance
bjeAsked:
Who is Participating?
 
mnhCommented:
Not precisely.
This means that error messages are redirected to ftp_message_file (that's the 2>$ftp_message_file part) and regular output is redirected to the same file as errors (that's 1>&2)

Also, if the script receives other than 2 parameters, it will fail with return code 16.

Regards,
-- mnh
0
 
omarfaridCommented:
Is this the complete script? I think something is missing or it has a syntax error with } after EOF

The script checks if it was called with two arguments and if not it exits with error code 16.

0
 
Murugesan NagarajanSubject-matter expert at C++ C delivery, implementation, at UNIX oriented operating systems (Windows: CYGWIN_NT MINGW32_NT MINGW64_NT)Commented:
As per the given statements, I feel that the following statements comes at the end of a function inside a script:
    bye
    EOF
    }
    #

If the 2 parameters are not passed to the script it will display the following in the output:
    ScriptName: usage ScriptName <file_to_transfer> <directory>
    ScriptName called with invalid number of parameters
    Processing Abnormally Terminated

Then the script is returning with the return code as "16".


The script will not return 16 if no file is present in the directory from the FTP session.

To get the error information from ftp function
Replace:
        bye
        EOF
        }
        #
With:
    bye
    EOF
    grep -w "226" $ftp_message_file
    if [ $? -eq 0 ]
    then
        echo "Successfull"
    else
        echo failure. Look into the file $ftp_message_file
    fi
    }
    #
OR
With:
    bye
    EOF
    grep -w "226" $ftp_message_file
    if [ $? -eq 0 ]
    then
        echo "Successfull"
    else
        echo failure. Look into the file $ftp_message_file
        exit anyNumberYouWish
    fi
    }
    #
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Murugesan NagarajanSubject-matter expert at C++ C delivery, implementation, at UNIX oriented operating systems (Windows: CYGWIN_NT MINGW32_NT MINGW64_NT)Commented:
In the given replacements
the following line:
           grep -w "226" $ftp_message_file
can be replaced with:
           grep -w "226" $ftp_message_file > /dev/null 2>/dev/null
0
 
bjeAuthor Commented:
So, the script will fail, if it does not pick up a file, correct?  The parameters the script is looking for is the file it is picking up?

Thank you for your help.
0
 
mnhCommented:
Hi,

The parameters the script is looking for are:
   1)  file_to_transfer
   2)  directory

If you don't specify both parameters, the script fill fail.

Regards,
-- mnh
0
 
bjeAuthor Commented:
Thanks.  This helps

bje
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.