Remotely passing value on system() or %x[]

Hi,

I want to execute a remote bash script that take one string argument by
using system() or %x[]. But the value argument is not transmited
remotely.

Here my program

def trait_fic(repfic)
Find.find(repfic) do |path|
unless FileTest.directory?(path)
dirc="#{path}".split(///)
puts “#{dirc[3]}\n”
system(‘plink -pw ppp [email protected] /tmp/essai.ksh #{dirc[3]}’)
end
end
end

trait_fic(‘I:/toto’)

I have got:

ruby essai0.rb

PTOTO -------------------------> This is done by puts “#{dirc[3]}\n”
<—
Le batch traité est

/tmp/mma/essai.ksh[36]: syntax error at line 214 : `“Nous traitons le
batch $BATH …n”’ unexpected

Is there any way to transmit remotely this value. I also try net/ssh
with no succes.
Thanks in Advance

Alle Wednesday 01 October 2008, Bikas De simex ha scritto:

unless FileTest.directory?(path)

ruby essai0.rb
Is there any way to transmit remotely this value. I also try net/ssh
with no succes.
Thanks in Advance

Are you aware that string interpolation doesn’t happen in single quoted
strings? Since argument to system is a string enclosed in single quotes,
the
command itself is

‘plink -pw ppp [email protected] /tmp/essai.ksh #{dirc[3]}’

instead of

‘plink -pw ppp [email protected] /tmp/essai.ksh PTOTO’

which, I guess, is what you want. To achieve this, you need to use a
double
quoted string:

system(“plink -pw ppp [email protected] /tmp/essai.ksh #{dirc[3]}”)

I hope this helps

Stefano

Stefano C. wrote:

Alle Wednesday 01 October 2008, Bikas De simex ha scritto:

unless FileTest.directory?(path)

ruby essai0.rb
Is there any way to transmit remotely this value. I also try net/ssh
with no succes.
Thanks in Advance

Are you aware that string interpolation doesn’t happen in single quoted
strings? Since argument to system is a string enclosed in single quotes,
the
command itself is

‘plink -pw ppp [email protected] /tmp/essai.ksh #{dirc[3]}’

instead of

‘plink -pw ppp [email protected] /tmp/essai.ksh PTOTO’

which, I guess, is what you want. To achieve this, you need to use a
double
quoted string:

system(“plink -pw ppp [email protected] /tmp/essai.ksh #{dirc[3]}”)

I hope this helps

Stefano

Ruby refused to interpolate #{dirc[3]} dispite I have tried the
following:

system(“plink -pw ppp [email protected] /tmp/essai.ksh #{dirc[3]}”)
system(‘plink -pw ppp [email protected] /tmp/essai.ksh “#{dirc[3]}”’)
system(“plink -pw ppp [email protected] /tmp/essai.ksh ‘#{dirc[3]}’”)
system(plink ‘-pw ppp [email protected] /tmp/essai.ksh #{dirc[3]}’)
system(plink “-pw ppp [email protected] /tmp/essai.ksh #{dirc[3]}”)
system(‘plink -pw ppp [email protected] /tmp/essai.ksh #{dirc[3]}’)

Any suggestion please !

Thanks in advance.

Alle Thursday 02 October 2008, Bikas De simex ha scritto:

Are you aware that string interpolation doesn’t happen in single quoted
which, I guess, is what you want. To achieve this, you need to use a
following:
Thanks in advance.
The third line should work. To be sure the falut is of missing
interpolation,
I’d suggest to break the call to system in two steps: first, build the
command
string, then call puts. While this shouldn’t affect the result, it
allows you
to see which is the command you’re going to execute with system. You can
do
something like this:

cmd = “plink -pw ppp [email protected] /tmp/essai.ksh #{dirc[3]}”
puts cmd
system(cmd)

What’s the output from the lines above?

Stefano

Stefano C. wrote:

Alle Thursday 02 October 2008, Bikas De simex ha scritto:

Are you aware that string interpolation doesn’t happen in single quoted
which, I guess, is what you want. To achieve this, you need to use a
following:
Thanks in advance.
The third line should work. To be sure the falut is of missing
interpolation,
I’d suggest to break the call to system in two steps: first, build the
command
string, then call puts. While this shouldn’t affect the result, it
allows you
to see which is the command you’re going to execute with system. You can
do
something like this:

cmd = “plink -pw ppp [email protected] /tmp/essai.ksh #{dirc[3]}”
puts cmd
system(cmd)

What’s the output from the lines above?

Stefano

Hi,

I have got:

ruby veilleur0.rb

PTOTO -----------> This is done by puts “#{dirc[3]}\n”<—
/tmp/mma/essai.ksh[36]: syntax error at line 214 : `“Nous traitons le
batch $BATH …n”’ unexpected
Le batch traité est

We do not have interpolation on system() since $BATH will be replace by
the value PTOTO.

Thanks a lot

Bikas De simex wrote:

Stefano C. wrote:

Alle Thursday 02 October 2008, Bikas De simex ha scritto:

Are you aware that string interpolation doesn’t happen in single quoted
which, I guess, is what you want. To achieve this, you need to use a
following:
Thanks in advance.
The third line should work. To be sure the falut is of missing
interpolation,
I’d suggest to break the call to system in two steps: first, build the
command
string, then call puts. While this shouldn’t affect the result, it
allows you
to see which is the command you’re going to execute with system. You can
do
something like this:

cmd = “plink -pw ppp [email protected] /tmp/essai.ksh #{dirc[3]}”
puts cmd
system(cmd)

What’s the output from the lines above?

Stefano

Hi,

I have got:

ruby veilleur0.rb

PTOTO -----------> This is done by puts “#{dirc[3]}\n”<—
/tmp/mma/essai.ksh[36]: syntax error at line 214 : `“Nous traitons le
batch $BATH …n”’ unexpected
Le batch traité est

We do not have interpolation on system() since $BATH will be replace by
the value PTOTO.

Thanks a lot

Hi,

It was my remote script that was wrong. Interpolation work.

system(“plink -pw ppp [email protected] /tmp/essai.ksh #{dirc[3]}”) work …!

Thanks again

Bikas De simex wrote:

system(“plink -pw ppp [email protected] /tmp/essai.ksh #{dirc[3]}”) work …!

Even better is:

system("/path/to/plink", “-pw”, “ppp”, “[email protected]”, “/tmp/essai.ksh”,
dirc[3])

This is because the argument array is passed as-is to the child process.
There is no shell performing line splitting. This eliminates a number of
potential errors and security holes, e.g. if dirc[3] contains spaces,
quotes, or other special characters subject to interpretation by the
shell.

I have the similar problem for which I tried the solutions in this mail
thread.

I could not succeed with the results.
Please suggest your solution.

Here is what I tried.

File some.txt contains following two lines
basetest
send REGISTER, recv 200

my script******
require ‘rio’ # get first 4 lines (as always in ruby indexing starts
at 0)

$filename = rio(‘some.txt’).lines[0…0]
$basecase = rio(‘some.txt’).lines[1…1]
temp = “#$basecase”
temp.gsub! /send/, “>”
temp.gsub! /recv/, “<”

#puts “#$filename”
#puts temp
#puts “#{temp}”

run = “sgen -t #$filename #{temp}”
puts run
#puts run
end of my script*

output*****
sgen -t basetest

REGISTER, < 200


Observed that ruby outputs them into next line :frowning:
Please let me know the solution for the same.

Naresh

Naresh R. wrote:

Observed that ruby outputs them into next line :frowning:
Please let me know the solution for the same.

String#chomp

i.e.

$filename = rio(‘some.txt’).lines[0…0].chomp
… etc

On 27.01.2009, at 09:32, Naresh R. wrote:

rubee.rb:25: private method `chomp’ called for [“basetest\n”]:Array
(NoMethodError)

As Brian already pointed it’s String#chomp not Array#chomp.
String#lines gives you an Enumerable::Enumerator.
Your range index will give you an Array:
$filename = rio(‘some.txt’).lines[0…0] #=> [“basetest\n”]

If you just want “basetest\n” then use:
$filename = rio(‘some.txt’).lines[0] #=> “basetest\n”
or
$filename = rio(‘some.txt’).lines.first #=> “basetest\n”

:frowning:

Cmon, you will get it, if you read the error message carefully.
Try your code in irb and then ask your objects with inspect()
or class() what they really are, maybe you have not the object
you thought.

Regards, Sandor
Szücs

$filename = rio(‘some.txt’).lines[0…0].chomp
… etc
When I tried the above, I am getting the error as follows

rubee.rb:25: private method `chomp’ called for [“basetest\n”]:Array
(NoMethodError)

:frowning:
Naresh