The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Redirect output mpang_ Shell Programming and Scripting 1 08-15-2007 05:57 AM
Redirect output to a file jimmyc UNIX for Dummies Questions & Answers 11 01-31-2007 08:34 AM
redirect output to file xadamz23 Shell Programming and Scripting 4 06-29-2006 08:20 AM
redirect output of FTP kcaluwae Shell Programming and Scripting 4 06-23-2005 05:45 AM
redirect output to file? slackware Shell Programming and Scripting 1 09-11-2003 11:57 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-31-2006
Registered User
 

Join Date: Mar 2006
Posts: 89
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
Reply With Quote
Forum Sponsor
  #2  
Old 04-02-2006
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Read the sftp man page - the -B option is for buffer, not batch. You would need the lowercase -b option for the batchfile.
Reply With Quote
  #3  
Old 04-03-2006
Registered User
 

Join Date: Feb 2006
Posts: 25
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.
Reply With Quote
  #4  
Old 04-03-2006
Registered User
 

Join Date: Mar 2006
Posts: 89
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!
Reply With Quote
  #5  
Old 04-03-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,326
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.
Reply With Quote
  #6  
Old 04-03-2006
Registered User
 

Join Date: Mar 2006
Posts: 89
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!
Reply With Quote
  #7  
Old 04-03-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,326
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'.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0