: I am trying to write an FTP script. The script is going to put a file from
: a unix box to a oracle box. When I run the script it asks me for a
: password. How would you hard code a username and password so it does not
: prompt for one:
: Here is my code:
: ftp nhq1--coor03dev <<eof 2>&1
: put /stage/agt/AGT_STD_COLL.AAW00010 d:\ora_utl
The session you need to emulate is this:
the_ftp_prompt> user username_goes_here password_goes_here
the_ftp_prompt> put /stage/agt/AGT_STD_COLL.AAW00010 d:\ora_utl
(The important part is the 'user' command to FTP.)
: Oh what is 2>&1 do? Where could I look for what they mean.
Short answer: It redirects standard error (stderr) to the
same place as stdout (stdout), so the two may be used as
if they were one intermingled file output stream.
It says "redirect file number 2 into the same place that
file number 1 is going." These file numbers are how shell
scripts deal with the open/read-write/close paradigm. There
happen to be three pre-opened files that every program
uses, called 0, 1, and 2. 0 is standard input, 1 is
standard output, and 2 is standard error. The reason this
'2>&1' thingy is often used is that most command-line
programs send error messages to the stderr file, and all other
output to the stdout file. When you look at a program
interactively, you don't really notice because stderr and
stdout are both mapped to the terminal screen. But when you
want to redirect the output with > or send it through a pipe
with |, then it starts to matter, because those normally only
redirect stdout, not stderr.
To see the difference, try this:
cat non_existing_filename > output_filename
The cat command does not find the file called "non_existing_filename"
and complains, note that the complaint doesn't end up in the
output filename, it ends up on the screen.
Now try this:
cat non_existing_filename > output_filename 2>&1
Now this time the error message ends up being in the contents
of the file: output_filename, instead of on the screen.
Steven L. Mading at BioMagResBank (BMRB). UW-Madison
B1108C, Biochem Addition / 433 Babcock Dr / Madison, WI 53706-1544