sakal
sakal

Reputation: 275

use cygwin from cmd.exe

is it possible to use cygwin from cmd.exe in Windows?

i want to do following

FOR /L %G in (1 1 100) DO sshpass -p "password" scp  E:\in\File%G.csv openstack@remotecomp:/testfiles/

transfer 100 files from windows to unix computer

now question:

can i use sshpass and scp from cmd.exe as long as cygwin is installed? or do i have to use cygwin terminal?

and do the files which i want to transfer neccessarily have to be in cygwin's folder?

goal is to use this one command in a BPEL activity, and as such there should not be any kind of user interaction when the command is run

Upvotes: 1

Views: 2350

Answers (1)

Mark Fisher
Mark Fisher

Reputation: 9886

You can use the full paths to the binaries, or create a wrapper script and call that to do the cygwin commands, e.g.

#!/bin/bash
# doit.sh wrapper script in home dir of cygwin user
echo "got args $@"

and call it from windows shell with

for /L %G in (1 1 100) DO c:\cygwin\bin\bash --login -c "/home/youruser/doit.sh %G"

in this case it prints 1..100 out, but your wrapper script can do all the ssh stuff it needs to instead.

For a more complex script, you can pass params from windows to the shell script like this:

#!/bin/bash
# callssh.sh
COUNT_NUM=$1
PASSWORD=$2
FILE_PATH=$(cygpath $3)

sshpass -p $PASSWORD scp $FILE_PATH openstack@whereever:/some/path/ 

and you'd call it with

for /L %G in (1 1 100) DO c:\cygwin\bin\bash --login -c "/home/youruser/callssh.sh %G your_password E:/in/File%G.csv"

Note the use of cygpath to convert from windows path style to something that cygwin understands. The SSH executable is a cygwin process so you need to convert to something it will be able to use.

Also, note the change from backslashes to forward slashes, again for some quirks in path separators between windows and cygwin.

If you have trouble with this (I can't test your code for you directly), then do this on a cygwin shell:

cygpath E:/path/to/file

and then check it outputs something like /e/path/to/file (or /cygpath/e/path/to/file if you haven't remapped our root drives).

Upvotes: 1

Related Questions