?
Solved

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

Posted on 2009-12-18
7
Medium Priority
?
746 Views
Last Modified: 2013-12-26
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
0
Comment
Question by:bje
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 3

Accepted Solution

by:
mnh earned 2000 total points
ID: 26084337
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 26089435
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
 
LVL 10

Expert Comment

by:Murugesan Nagarajan
ID: 26094290
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:Murugesan Nagarajan
ID: 26094295
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
 

Author Comment

by:bje
ID: 26096039
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
 
LVL 3

Expert Comment

by:mnh
ID: 26096134
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
 

Author Comment

by:bje
ID: 26096167
Thanks.  This helps

bje
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question