Home > Archive > PERL Beginners > August 2005 > using system to run ssh $host command
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
using system to run ssh $host command
|
|
| Grover Mitchell 2005-08-24, 6:56 pm |
| Hi,
I am trying to use system to run a command on a remote machine.
system "ssh", $remote_host[0], "sudo", "-u", "nobody",
"/usr/bin/remote_command", "--arg1", $arg1, "--arg2", $arg2;
The problem I run into is that perl will ssh into the remote host and
give me a shell there, instead of running the remote command on the
remote system. When I exit, perl will then try and run the remote
command on my local host. Is there an easy way to accomplish this task
using system?
Thanks for any help.
| |
| Wiggins d'Anconia 2005-08-25, 3:55 am |
| grover mitchell wrote:
> Hi,
>
> I am trying to use system to run a command on a remote machine.
>
> system "ssh", $remote_host[0], "sudo", "-u", "nobody",
> "/usr/bin/remote_command", "--arg1", $arg1, "--arg2", $arg2;
>
> The problem I run into is that perl will ssh into the remote host and
> give me a shell there, instead of running the remote command on the
> remote system. When I exit, perl will then try and run the remote
> command on my local host. Is there an easy way to accomplish this task
> using system?
>
> Thanks for any help.
>
I haven't tested, but there haven't been any other responders yet so I
thought I would chime in.
Have you tried the one argument form of C<system>? There is the
potential for the above to be getting screwed up by the 'exec' rather
than the 'execvp' mentioned in,
perldoc -f system
I suppose. Try joining all of your arguments along with the command into
a single string passed to system and see if that helps. Of course you
could always try Net::SSH::Perl as a substitute.
You also ought to consider using a full path to ssh, and I assume the
above is just a snippet of a larger set of code that does proper error
checking/handling per the C<system> docs ;-)...
HTH,
http://danconia.org
| |
| Dhanashri Bhate 2005-08-25, 3:55 am |
| -> grover mitchell wrote:
-> > Hi,
-> >=20
-> > I am trying to use system to run a command on a remote machine.
-> >=20
-> > system "ssh", $remote_host[0], "sudo", "-u", "nobody",
-> > "/usr/bin/remote_command", "--arg1", $arg1, "--arg2", $arg2;
-> >=20
-> > The problem I run into is that perl will ssh into the=20
-> remote host and
-> > give me a shell there, instead of running the remote command on the
-> > remote system. When I exit, perl will then try and run the remote
-> > command on my local host. Is there an easy way to=20
-> accomplish this task
-> > using system?
Hi,
I had done something like this long back, which works.
so you can try it...
****************************************
*********
$machine=3D"remotemachine";
$prog=3D"/path/to/prog arg1 arg2 arg3";
$remote_command =3D "ssh nobody\@$machine $prog";
system($remote_command);
****************************************
*********
Note: in my case both the machines use NIS.
Hope this helps;
Dhanashri
=20
| |
| Pablo Wolter 2005-08-25, 7:59 am |
| Hi:
Try this:
<variable_to_store> = `rsh -l <username> <hostname> 'command arg1 arg2 ..`;
This works for me, I don't know if this is the best way or if it the more
secure way to run a command in a remore machine, try to search CPAN for a
module that can do something similar.
Pablo.
On 8/24/05, grover mitchell <baguagrover@gmail.com> wrote:
>
> Hi,
>
> I am trying to use system to run a command on a remote machine.
>
> system "ssh", $remote_host[0], "sudo", "-u", "nobody",
> "/usr/bin/remote_command", "--arg1", $arg1, "--arg2", $arg2;
>
> The problem I run into is that perl will ssh into the remote host and
> give me a shell there, instead of running the remote command on the
> remote system. When I exit, perl will then try and run the remote
> command on my local host. Is there an easy way to accomplish this task
> using system?
>
> Thanks for any help.
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
--
(o_ Pablo Wolter
//\ Usuario #284649
V_/_ Debian Sid Kernel 2.6.8
| |
| Manav Mathur 2005-08-25, 7:59 am |
| Hi:
Try this:
<variable_to_store> = `rsh -l <username> <hostname> 'command arg1 arg2 ..`;
This works for me, I don't know if this is the best way or if it the more
secure way to run a command in a remore machine, try to search CPAN for a
module that can do something similar.
Pablo.
On 8/24/05, grover mitchell <baguagrover@gmail.com> wrote:
>
> Hi,
>
> I am trying to use system to run a command on a remote machine.
>
> system "ssh", $remote_host[0], "sudo", "-u", "nobody",
> "/usr/bin/remote_command", "--arg1", $arg1, "--arg2", $arg2;
>
> The problem I run into is that perl will ssh into the remote host and
> give me a shell there, instead of running the remote command on the
> remote system. When I exit, perl will then try and run the remote
> command on my local host. Is there an easy way to accomplish this task
> using system?
>
> Thanks for any help.
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
--
Did you try Net::SSH ??
Manav
|
|
|
|
|