Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Command Executing problem in perl.

by mantager (Sexton)
on Jun 27, 2012 at 12:57 UTC ( #978648=note: print w/replies, xml ) Need Help??

in reply to Command Executing problem in perl.

Hi leslie,
I'm having troubles parsing the command line as you wrote it, so maybe your shell is having troubles, too.
What's the command that's supposed to run on the remote machine? I mean: can you tell us how you would write it if you were on the remote machine's shell?
Also, note that the remote shell is trying to redirect output on the file "3/1/12,name=DISASTER_RECOVERY: -av" because of the first > in the command line.

I tried this:

my @cmd = ('ssh', '-x', 'user@remotehost', '"ls -la > mylsfile"'); my @output = qx/@cmd/;

@output is empty, since all the output was redirected into the file "mylsfile" on the remote host. I suppose this is more or less what you're trying to accomplish. Maybe trying to split the command into an array may help you sort out the quotes.
If I right interpreted your command, what you're trying to do is:
my @cmd = ( 'ssh', '-x', '-i', '~/.ssh/bkp', '<server name>', q[mminfo -q "savetime>3/1/12,name=DISASTER_RECOVERY:\\\\" -av -ot - +r client >/home/rbr/clnts] );

I'm not sure how many \ you will need on that command line (assuming you're trying to put some \ after that colon).

Replies are listed 'Best First'.
Re^2: Command Executing problem in perl.
by leslie (Pilgrim) on Jun 28, 2012 at 04:34 UTC

    Hi mantager,
    Thanks for ur input.
    This below command should have to run in the remote machine and output should be redirect to the file.

    mminfo -q "savetime>3/1/12,name=DISASTER_RECOVERY:\\" -av -ot -r clien +t >/home/rbr/clnts

    I am executing this command from my local machine using perl script through SSH as I said earlier.
    I have tried to create the output file in the remote machine. But now I am cleared that, we can't create the output file in the remote machine
    by redirecting the output from one of our monks reply.

    - After colon there should be two slash.
    - We can use single quotes also instead of double quotes.

      Hi leslie.
      Creating the file on the remote machine is not impossible, it's only a matter of quoting the string the right way.
      In your case, it's also a matter of isolating that > sign you have inside your parameters, because otherwise it's interpreted by the remote shell as a redirection.

      With this:

      my @cmd = ( 'ssh', '-x', $remotehost, q['mminfo -q "savetime>3/1/12,name=DISASTER_RECOVERY:\\\\" -av -ot + -r client > /home/rbr/clnts'] ); print qx/@cmd/;
      you should get the result you expect. I assumed the \ after the colon is just one, because if you launch directly the command:
      mminfo -q "savetime>3/1/12,name=DISASTER_RECOVERY:\\" \ -av -ot -r client >/home/rbr/clnts
      from the shell, one of the \ is eaten by the shell. The four \\\\ should be equivalent. I tried this with a "mminfo" command that is just a script echoing its arguments, and this is what I get:
      -q savetime>3/1/12,name=DISASTER_RECOVERY:\ -av -ot -r client
      and it's written in a file on the remote machine.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://978648]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (None)
    As of 2017-09-22 03:50 GMT
    Find Nodes?
      Voting Booth?
      During the recent solar eclipse, I:

      Results (257 votes). Check out past polls.