This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: scripting sftp in a bash script


On 2003-12-02, James Hu <jxh@despammed.com> wrote:
> On 2003-12-02, David Strozzi <dstrozzi@MIT.EDU> wrote:
>> I'm trying to use sftp within a bash script on cygwin (version 1.5.5
>> on winXP pro).  Ideally I'd like to use a 'here document' rather than
>> using an external batchfile...
>>
>> ... are there other ways to script/call sftp (or a _secure_
>> equivalent)?
>
> sftp has its own batch file facility.  ...

David followed up with me directly.  I am posting a summary of our
exchange here for the archives:

David Strozzi <dstrozzi@mit.edu> wrote:
> Thanks.  I'm aware of that, but here documents have the advantages
> of not having two separate files to keep track of, and you can use
> variables defined in the script in the commands. batchfiles may be the
> only solution and they will work, but be a bit awkward.

In your script, you can use a here document directed into cat,
and redirect the output of cat into a temporary file which is
used as the batch file for sftp.  When sftp completes, you can
remove the temporary file.

  $ cat <<. > foo.txt
  > Hello
  > world!
  > .
  $ cat foo.txt
  Hello
  world!
  $

-- James


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]