0

I am running a bat file from windows command line which calls a linux script to copy a file:

WIN_BATCH.bat content:

"C:\plink.exe" -ssh User@%1 -pw "pass123" "/u01/./LINUX_COPY_SCRIPT.sh %1"

LINUX_COPY_SCRIPT content as below:

sshpass -p "pass123" scp /u01/file_1.txt root@$1:/u01/file_1_Copy.txt

When I am running command from Win cmd as below, evereything is working fine, i.e. 

Win command prompt:

C:\Scripts>WINbatch.bat 11.111.11.11

Message in CMD:

C:\Scripts>"C:\plink.exe" -ssh [email protected] -pw "pass123" "/u01/./LINUX_COPY_SCRIPT.sh 11.111.11.11"
C:\Scripts>

And the file gets copied from "file_1.txt" to "file_1_Copy.txt"

Now comes the issue, if I modify my scripts as below:

WIN_BATCH.bat content:

"C:\plink.exe" -ssh User@%1 -pw "pass123" "/u01/./LINUX_COPY_SCRIPT.sh %2"

LINUX_COPY_SCRIPT content as below:

sshpass -p "pass123" scp /u01/file_1.txt root@$2:/u01/file_1_Copy.txt

and pass 2 parameter:

Win command prompt:

C:\Scripts>WINbatch.bat 11.111.11.11 11.111.11.11

I'm getting error:

C:\Scripts>"C:\plink.exe" -ssh [email protected] -pw "pass123" "/u01/./LINUX_COPY_SCRIPT.sh 11.111.11.11"
ssh: Could not resolve hostname : Name or service not known
lost connection
C:\Scripts>

WHY ?? If you see the commands fired in both cases are same, as i am passing the same parameter.

HOW I CAN GET THIS WORKING ? The idea to pass multiple parameter because i want to copy file from one env to other at later stage.

I.e. once 

C:\Scripts>WINbatch.bat 11.111.11.11 11.111.11.11 

is working I'll be doing 

C:\Scripts>WINbatch.bat 11.111.11.11 11.111.11.12

Where "11.111.11.11" and "11.111.11.12" are ip of 2 systems.

5
  • Why not install Cygwin and write real shell scripts instead of crummy DOS bat files? Commented Jul 31, 2018 at 6:30
  • Yeah, but i cant install Cygwin, so need to figure out something which i have... Commented Jul 31, 2018 at 6:32
  • Also I don't see any mistake in this approach, passing multiple parameters is absolutely fine in windows batch file but not sure whats the issue here, even when i am using the same parameter twice.. Commented Jul 31, 2018 at 6:43
  • From the batch you only pass one argument %2 so the shell script can't access $2 as it is not present. Commented Jul 31, 2018 at 7:28
  • Thanks everyone for helping me on this issue.. Commented Jul 31, 2018 at 13:41

1 Answer 1

1

You are passing only one argument to LINUX_COPY_SCRIPT.sh:

"C:\plink.exe" -ssh User@%1 -pw "pass123" "/u01/./LINUX_COPY_SCRIPT.sh %2"

But you are trying to use second argument ($2) in the shell script:

sshpass -p "pass123" scp /u01/file_1.txt root@$2:/u01/file_1_Copy.txt

It should be $1:

sshpass -p "pass123" scp /u01/file_1.txt root@$1:/u01/file_1_Copy.txt
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Martin, This make sense

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.