Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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).

Comment on Re: Command Executing problem in perl.
Select or Download Code
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2015-12-02 01:35 GMT
Find Nodes?
    Voting Booth?

    My keyboard shows this many letters:

    Results (31 votes), past polls