3

I am trying to pass arguements to a local script to be executed on a remote machine. The script works fine as I have tested it passing variables in manually. I am trying to use plink for this. I take in username (arg to be passed to script) and need to send it along with the script via plink. The command I'm using is:

plink.exe ubuntu@192.168.198.128 -m "myLocalScript.ksh"   

I have also tried:

plink.exe ubuntu@192.168.198.128 -m "myLocalScript.ksh %username%"   

plink.exe ubuntu@192.168.198.128 -m %username% < "myLocalScript.ksh"   

I've tried piping the arguments in, and adding them to various places in the command etc. Does anyone know how I can achieve this?

Edit: I am using this from cmd.exe rather than cygwin. They -m option does the following:

-m file   read remote command(s) from file
Cen92
  • 171
  • 1
  • 13
  • or print -- `${.sh.version}` if above doesn't work. Good luck. – shellter Jan 16 '13 at 17:23
  • 1
    `plink.exe` and `%username%` implies that you're using a Windows-based cmd-line? Are you using cgywin or cmd.exe? Your redirection into `plink` will likely fail, unless you really have `"myLocalScript.ksh "` as a fileName (with the trailing " " char). I assume that's a typo? Consider editing your post to remind us what the `-m` argument does. `cmd.exe` sytnax would normally be `/m`, or do you have doc that says its OK to use `-m`. Also, make the simplest possible test script for testing this, maybe just `ls` inside a script? Good luck. – shellter Jan 16 '13 at 18:41
  • Hi Shelter, I've edited the question to try make it clearer. – Cen92 Jan 17 '13 at 09:12
  • I don't see an example of your attempt at piping but only redirecting. Did you omit it because it didn't work? Might help to include the lines you tried and results from each failure. – Lizz Mar 01 '13 at 07:31

1 Answers1

1

The -m option has no mechanism for passing attributes it just literally runs the file as is. The problem is that your korn shell script has no interpreter in the local end so there's no mechanism for this in your windows end but do try this:

plink ubuntu@192.168.198.128 "tr -d '\r'| ksh -s %username%" < myLocalScript.ksh 

Better yet make the main call more readable:

call :remotecmd ubuntu@192.168.198.128 myLocalScript.ksh %username%


exit /B
:remotecmd 
  setlocal
    for /f "tokens=2,*" %%i in ("%*") do set options=%%j
    plink %1 "tr -d '\r'| ksh -s %options%" < %2
  endlocal
exit /B

The command is now generalized to handle any number of additional switches.

joojaa
  • 4,354
  • 1
  • 27
  • 45