4

I need to execute a batch script which runs the shell script remotely inside the Linux box.

Now, everything is working fine, but the script fails to execute if I try to give a command line parameter to the shell script.

Working -> ex

C:\temp\Testing>putty.exe -pw "blabla" -m "test-script.sh" [email protected]

But if I try to give arguments it fails to execute. Example:

Not Working

C:\temp\Testing>putty.exe -pw "blabla" -m "test-script.sh ok-1" [email protected]

 where ok-1 = command line argument for local script test-script.sh

How can I fix this problem?

4
  • From the documentation : "the `-m' option expects to be given a local file name, and it will read a command from that file." Commented Jun 12, 2012 at 17:19
  • @dystroy, thanks for the suggestion. What I draw from your response is , your suggesting me to use -m option, . I have used -m option and it wors like a charm but if i want my bash script (which resides locally) to accept command line argument ( ok-1 in this case ) how would i implement that Commented Jun 12, 2012 at 21:35
  • @samantha - I don't think you can achieve what you are trying through the -m option. -m option is to provide a command text file and that command text file is taken as is and executed on target server. -m as far as I know, is not designed to consider what follows as a command line syntax. Instead -m tells putty to grab the file mentioned after -m and execute it remotely. So, when you provide a command line argument, say ok-1, putty thinks of ok-1 as a file.HTH. I can provide an alternate way to do what you are trying to achieve. Commented Jun 12, 2012 at 21:59
  • @ring bearer, Thanks a lot for detailed explanation. your solution has cleared few of my doubts. Commented Jun 12, 2012 at 22:58

1 Answer 1

6

Instead of using putty.exe, you can use pscp and plink (utilities that come with PuTTY) to do this. Use a command like this:

pscp.exe -pw "blabla" test-script.sh [email protected]:/some/path/

to copy the script to the remote server, and then use a command like this:

plink.exe -ssh -pw "blabla" [email protected] /some/path/test-script.sh ok-1

to execute it.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for solution. Being late in Uk , I will try it tomorrow in office and let you guys know if it works. Thanks again
Hi @bta, I tried your command from cmd.exe on window but it fails . I got error like "bash: ok-1: command not found"
@samantha- Whoops, I made a typo on my plink command. There shouldn't be a colon between the server address and the command to run. See my edited answer for the correct syntax.

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.