1748249 Members
3551 Online
108760 Solutions
New Discussion юеВ

SFTP in batch mode

 
Mark Battle
Advisor

SFTP in batch mode

SFTP works for me in interactive mode, but not when I try to use the batch option. Then there is no output.

$ ty ls.txt
pwd
ls
quit
$ set ver
$ define/user sys$command nl:
$ sftp "-B" ls.txt user@host
$ set nover

The same occurs when I submit it as a batch job.

tcpip sh version

HP TCP/IP Services for OpenVMS Alpha Version V5.5 - ECO 1
on an AlphaStation DS15 running OpenVMS V8.2

Any ideas what I am doing wrong? How can I see the output.

10 REPLIES 10
Duncan Morris
Honored Contributor

Re: SFTP in batch mode

Hi Mark,

ssh/sftp/scp in BATCH mode REQUIRES "passwordless" authentication such as publickey or hostbased.

You cannot supply a password in batch mode.

Use the itrc search facility to see several threads on using sftp in batch mode on OpenVMS.


http://h30499.www3.hp.com/t5/Networking/Using-SFTP-in-a-batch-job/m-p/4777756#M9817


There are quite a lot of threads with examples of capturing output from sftp and/or ssh batch procedures.

http://h30499.www3.hp.com/t5/Languages-and-Scripting/SSH-capturing-output-within-a-PIPE-stream/m-p/5267853#M12767
Duncan

Mark Battle
Advisor

Re: SFTP in batch mode

Sorry I should have stated that I am using public/private keys and not passwords.

Anyway if I was using passwords, I would have expected to see an error message.
Steven Schweda
Honored Contributor

Re: SFTP in batch mode

> [...] V5.5 - ECO 1

Is that the latest ECO? (I'd look for
myself, if I still had any useful patch
access.) If not, then that'd be my first
step.

> [...] How can I see the output.

Uh, stop sending it to NL:? I'd say that the
time to start thinking about using NL: for
anything is _after_ you get something to
work.

A Forum search for keywords like, say:
sftp batch
should find some examples where this worked.
Mark Battle
Advisor

Re: SFTP in batch mode

I tried it first without
define/user sys$command nl:

I added that line because a search here for sftp batch suggested that that was a good thing to do.
Steven Schweda
Honored Contributor

Re: SFTP in batch mode

> I added that line because a search here for
> sftp batch suggested that that was a good
> thing to do.

If only my psychic powers were stronger, then
I might be able to see your search results.
_Then_ I might be able to judge the value of
that suggestion. (Or even know that it had
no effect.)

_My_ search results included this:

http://h30499.www3.hp.com/t5/Networking/Using-SFTP-in-a-batch-job/m-p/4777756#M9817


which seems to offer a pretty similar working
example.

> Is that the latest ECO?

Still wondering. TCPIP is seldom bug-free,
but any version that old with only one ECO
seems to me to be a poor risk.

Duncan Morris
Honored Contributor

Re: SFTP in batch mode

Mark,

even with a current version of TCPIP services

$tcpip show ver

HP TCP/IP Services for OpenVMS Alpha Version V5.7 - ECO 2
on an AlphaServer 400 4/166 running OpenVMS V8.4

the procedure never terminates, if you redefine sys$command when run in batch or interactive mode. The issuing process returns the file list, but never processes the command following the ls, remaining in a loop.

Drop the "define", and the job runs correctly. See the attached output from 2 runs.

Duncan

Mark Battle
Advisor

Re: SFTP in batch mode

Duncan,

Strange. My script does not hang. With or without the define no output is produced.

I introduced the define as a result of the following thread
http://h30499.www3.hp.com/t5/General/Redirecting-output-from-sftp/m-p/5264499#M27630


Here Joerg Mohren also sees looping. I have now followed the solution of RBrown, but this resulted in an empty output file.

Walt McGaw
Occasional Advisor

Re: SFTP in batch mode

Hello Mark,

Here is a working example of what you are trying to do performed on my system. You'll just need to modify a few things to match your environment.

$! Main procedure submitted to batch
$!
$ type sftp_hprc.com
$ set verify
$ define/nolog sys$login SYS$SYSROOT:[W_MCGAW]
$ set def SYS$SYSDEVICE:[W_MCGAW]
$ create ls.txt
$ deck
pwd
ls
$ eod
$ sftp "-Bls.txt" W_MCGAW@HOSER

Command to submit:

$ submit/noprint/log=SYS$SYSDEVICE:[W_MCGAW]SFTP_HPRC.LOG/notify SFTP_HPRC.COM

Job SFTP_HPRC (queue SYS$BATCH, entry 99) started on SYS$BATCH

Job SFTP_HPRC (queue SYS$BATCH, entry 99) completed

The log file that was created:

$ TYPE SFTP_HPRC.LOG
$ Set NoOn
$ VERIFY = F$VERIFY(F$TRNLNM("SYLOGIN_VERIFY"))
%SET-W-NOTSET, error modifying DKC0:
-SET-E-INVDEV, device is invalid for requested operation
11-MAY-2011 07:35:22
$ define/nolog sys$login SYS$SYSROOT:[W_MCGAW]
$ set def SYS$SYSDEVICE:[W_MCGAW]
$ create ls.txt
pwd
ls
$ sftp "-Bls.txt" W_MCGAW@HOSER



Welcome to OpenVMS (TM) Alpha Operating System, Version V8.3

Warning: Converting file ls.txt to Stream_LF.
Warning: File ls.txt converted successfully to Stream_LF.
sftp> pwd

SYS$SYSDEVICE:[W_MCGAW]
sftp> ls



.
ACCOUNTING_LOGS.DIR;1
BACKUP.COM;2
BACKUP.COM;1
BUILD_DCL.COM;10
CONTAINER.BCK;4
.
.
.
ZIP-ALPHA.EXE;1

W_MCGAW job terminated at 11-MAY-2011 07:35:24.41

Accounting information:
Buffered I/O count: 369 Peak working set size: 10336
Direct I/O count: 92 Peak virtual size: 189056
Page faults: 1315 Mounted volumes: 0
Charged CPU time: 0 00:00:00.07 Elapsed time: 0 00:00:02.15


This seems to do what you are looking for. Hopefully witha few small tweaks, you can make this work in your envirnoment.

If not, maybe you can log a call with HP OpenVMS Support for assistance.

Best regards,
Walt McGaw
Mark Battle
Advisor

Re: SFTP in batch mode

Problem solved.
The batch file must be created with Stream_LF format. I had used DCL Create.

Thanks anyway.