I want to login to a Linux environment say ENV1 and run a command from ENV1, to copy a file from ENV1 to ENV2 automatically.
Everything is working fine when i am using below commands.
I am running "BATCH_FILE.bat" which reads command from "COMMANDS_TO_RUN_IN_LINUX.bat" file, to copy file from ENV1 to ENV2.
BATCH_FILE.bat file content as below:
"C:\putty.exe" -ssh myuser_ENV_ONE@ENV1_ipaddress -pw "mypassword_ENV_ONE" -m "C:\COMMANDS_TO_RUN_IN_LINUX.bat"
COMMANDS_TO_RUN_IN_LINUX.bat content as below:
sshpass -p "mypassword_ENV_TWO" scp /u01/file.txt myuser_ENV_TWO@ENV2_ipaddress:/u01/file.txt
Now comes the issue, I want user to pass both the environment ipaddress(ENV1 and ENV2) rather then hard coding and for that I modified the command as below:
Modified BATCH_FILE.bat file content as below:
"C:\putty.exe" -ssh myuser_ENV_ONE@%1 -pw "mypassword_ENV_ONE" -m "C:\COMMANDS_TO_RUN_IN_LINUX.bat"
COMMANDS_TO_RUN_IN_LINUX.bat content as below:
sshpass -p "mypassword_ENV_TWO" scp /u01/file.txt myuser_ENV_TWO@%2:/u01/file.txt
I'm passing ENV1 detail while running the BATCH_FILE.bat from command line and its working fine and is getting logged in ENV1.
But I have no idea now to pass the ENV2 as well which in turn will replace %2.
I tried using %1 instead just to check if the parameter %1 is getting passed from BATCH_FILE.bat to COMMANDS_TO_RUN_IN_LINUX.bat and in turn it will copy file from ENV1 back to ENV1.
But that also gave me an error "unknown host %1" .i.e. it wasn't passed as parameter.
I have gone through some posts but none of them has resolved my issue.