Redirect output from sFTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Redirect output from sFTP
# 1  
Old 03-31-2006
Redirect output from sFTP

Hey all,

I have a ksh script which used ftp to transfter certain files to a AIX server, however, now I have to switch to sFTP and I have the following problem. Originally,

output=`ftp -nv $AIX_HOST << EOF 2>&1
user $AIX_USER $AIX_PASSWORD
cd /hsbc/risdev/risdevhfi/app/ftp/incoming
put "$filename"
quit
EOF`

Now, I am using sFTP I don't know if I can do something like this

output=sftp -B $BATCHFILE $AIX_USER@$AIX_HOST

If not, what am I suppose to do to get the output from the sFTP? thanks!

Later,
Pang
# 2  
Old 04-02-2006
Read the sftp man page - the -B option is for buffer, not batch. You would need the lowercase -b option for the batchfile.
# 3  
Old 04-03-2006
Hi
Try this
sftp $SFTP_USER@$SFTP_HOST yes <<-!
lcd $DATA_DIR
cd $SFTP_REMOTE_DIR
put $REPORT
quit
!

Remember for Sftp we cant suppply password as part of acript.So you need to generate a passowrd less key and get the public key and put that public key in $HOME/.ssh/known_hosts file or similar file under .ssh directory in your home directory. The passwordless key can be genarted using ssh-key gen program.

Hope this helps.
# 4  
Old 04-03-2006
reddymails, would you please explain what this "<<-!" means?

I am new with scripting so I know very little and if you don't mind me asking what is the difference between "<<" and "<", I see people use them quite often. Thanks!
# 5  
Old 04-03-2006
mpang_, the <<-! that reddymails has used is exactly the same as the <<EOF that was in use in your script before.

The use of the '<<' operator is explained in the man page of ksh:
Quote:
<<[-]word
The shell input is read up to a line that matches word, or to an end-of-file. No parameter substitution, command substitution, or file name generation is performed on word. The resulting document, called a here-document, becomes the standard input. If any character of word is quoted, no interpretation is placed upon the characters of the document. Otherwise, parameter and command substitution occurs, \new-line is ignored, and \ must be used to quote the characters \, $, `, and the first character of word. If - is appended to <<, all leading tabs are stripped from word and from the document.
In case that is confusing, the basic gist is that using the <<, you can pre-provide input to the shell till the word that immediately follows the '<<' is again encountered. The shell will then execute the input line by line just like a script.
# 6  
Old 04-03-2006
So...does it mean

sftp $SFTP_USER@$SFTP_HOST yes <<-! 2>&1

will provide the output that I need?

"<<-!" or "<<EOF" read the output until end of file and then ">" redirect that output to where I want? thanks guys!
# 7  
Old 04-03-2006
You've almost got it. Just that in your statement
Quote:
and then ">" redirect that output to where I want?
the std output is not redirected anywhere. The stderr is, however, redirected to the output.

Also, the 'read the output till end of file' should be 'read the input till the end of file'.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirect script output to a file and mail the output

Hi Guys, I want to redirect the output of 3 scripts to a file and then mail the output of those three scripts. I used below but it is not working: OFILE=/home/home1/report1 echo "report1 details" > $OFILE =/home/home1/1.sh > $OFILE echo... (7 Replies)
Discussion started by: Vivekit82
7 Replies

2. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

3. AIX

Not able to redirect output of command

Hi All,. We are using AIX as the OS to host the Oracle ERP. We have a command FNDLOAD which is used to load setups. When this command is run, it outputs names of log files and any errors to the screen. I am trying to redirect this output to a file because we have large number of these... (4 Replies)
Discussion started by: mansmaan
4 Replies

4. Shell Programming and Scripting

Redirect SFTP Output only

HI Guys, My requiement is to redirect output and error of sftp to a file.I have gone through few solutions given in this forum and got the alternate solution but not the one i want. Below piece of code is not working .. $ sftp user@server<<EOF 2>&1 >temp.txt > cd <dir> > ls > EOF... (0 Replies)
Discussion started by: mohanpadamata
0 Replies

5. Shell Programming and Scripting

How to redirect output of ls to a file?

Hi All, I want to redirect only the file names to a new file from the ls -ltr directroy. how Can i do it. my ls -ltr output will be as below. -rwxr-xr-x 1 118 103 28295 Jul 26 2006 event.podl -rwxr-xr-x 1 118 103 28295 Jul 26 2006 xyz.podl I want my new file... (6 Replies)
Discussion started by: girish.raos
6 Replies

6. Shell Programming and Scripting

output redirect

Hi i am compiling a source code by make command. i want to redirect the output of make to a file but at the same time i want to see the output in terminal. how to do this ?. please suggest your idea. thanks in advance. Saravana ---------- Post updated at 05:24 PM ----------... (2 Replies)
Discussion started by: tsaravanan
2 Replies

7. Shell Programming and Scripting

Redirect Output

Hi, I would like to list files: ls *.hdf But I would like a copy of the output directed to the screen, but also APPENDED to a text file: test.txt I have tried: ls *.hdf | tee test.txt However, that will just write over everything already existing in test.txt. How can I append the... (1 Reply)
Discussion started by: msb65
1 Replies

8. Shell Programming and Scripting

Redirect output

Hi all, I have a script which call a java program, the logging (to log file) in the program is done using log4j. However, as a safety measure, i still choose to direct standard error to another log file as follow /usr/bin/java -classpath ${classpath} -Xmx128m TestingProgram 2>>... (1 Reply)
Discussion started by: mpang_
1 Replies

9. UNIX for Dummies Questions & Answers

Redirect Output In Variable

how make assign the output of the command (for example: grep "file" "string" ) in a variable ($name)? i thing how put the result of the command (grep , cut, find ecc) in a variable.. IT's Possible ?? (1 Reply)
Discussion started by: ZINGARO
1 Replies

10. Shell Programming and Scripting

Redirect the output of prstat

Hi, How to redirect the output of prstat command to a file. Ex: I want to do like this while : do prstat >> prs.log sleep 5 done is it possible ???? if No, then how can i proceed?? PLEASE HELP ME OUT FROM THIS :confused: Thanks in advance ----------- (2 Replies)
Discussion started by: vastare
2 Replies
Login or Register to Ask a Question