Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: back tick to do ssh

by convenientstore (Pilgrim)
on Dec 31, 2007 at 00:36 UTC ( [id://659676]=note: print w/replies, xml ) Need Help??


in reply to Re: back tick to do ssh
in thread back tick to do ssh

You are right. My example is not enough and I assumed what was happening.
It is however my intention that entire commands run on remote machine but results being shown in the local machine.
I will try others and get back to you on this

Replies are listed 'Best First'.
Re^3: back tick to do ssh
by kirillm (Friar) on Dec 31, 2007 at 00:47 UTC

    Hi convenientstore,

    Enclose the command you want to be executed on the remote host in quotes, like this:

    my $result = `ssh host1 'echo something | /bin/others'`;

    This way echo something | /bin/others will be run on host1 and the result will end up in $result.

      That sort of solution would be okay for toy examples and really simple cases, but as soon as you get to situations involving real work, the constraints of quoting and escaping things for shell command operations can get really hairy and unworkable. It's the proverbial road to hell, paved with good intentions.

        Sure it is! ;-) Putting everything in a shell script on the remote server and running that script, rather than juggling with quotes, escapes and pipes is easier, safer and gives more predictable results...

Re^3: back tick to do ssh
by graff (Chancellor) on Dec 31, 2007 at 00:44 UTC
    If you want to run any sort of complex (pipeline or other sequential) operation entirely on a remote host, you will probably want to use a module. If, for reasons no one else can fathom, you really don't want to use a module, you'll need to break your complex operations down into simple, single-step-at-a-time commands and waste a lot of time doing a series of backtick operations to slog through the sequence.

    Either that, or else you'll simply want to create a script on the remote machine that does everything you want, and run that as a single backtick operation from your local perl script.

      Unfortunately, our system's perl is pretty old,
      This is perl, version 5.005_03 built for sun4-solaris Copyright 1987-1999, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5.0 source +kit. Complete documentation for Perl, including FAQ lists, should be found +on this system using `man perl' or `perldoc perl'. If you have access to + the Internet, point your browser at http://www.perl.com/, the Perl Home Pa +ge.
      and I can't use the module that I wanted to use
      userX@myserver ~/script> perl -c scriptX.pl Weak references are not implemented in the version of perl at /home/us +erX/script/pm/Net-SSH-Perl-1.30/lib/Net/SSH/Perl/Packet.pm line 22 BEGIN failed--compilation aborted at /home/userX/script/pm/Net-SSH-Per +l-1.30/lib/Net/SSH/Perl/Packet.pm line 22. BEGIN failed--compilation aborted at /home/userX/script/pm/Net-SSH-Per +l-1.30/lib/Net/SSH/Perl.pm line 6.
      I will try to run stuff from remote by other script and just extract it
        I feel your pain (there are still some old suns where I work, still running an ancient version of perl). Here's an idea that might keep things coherent for you. if the stuff that needs to be done on the remote box is always the same, there's no problem: put a shell or perl script there to do the job, and run that from your local machine via ssh in backticks.

        But if the remote actions need to vary for whatever reason, your local perl script could probably build the necessary script that would need to run on the remote machine, save it to a local file, "scp" it to the remote box, and then run it via ssh in backticks. (But usually you can set it up so only one version of the remote script is needed, and it uses command-line args to handle the necessary variations.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://659676]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-05-28 20:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found