Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Run Remote Command Via SSH

by Anonymous Monk
on Nov 06, 2012 at 00:34 UTC ( [id://1002404]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,
I'm trying to do something that should be simple but for some reason, I guess I'm just bored and making it difficult. I'm trying to run a command on a remote computer via SSH. The remote computer has the port changed for SSH and I need to use a key to connect. I first tried Net::SSH::Perl but I kept running into the "Received disconnect message: Too many authentication failures for abc at ~ ~ ~ AuthMgr.pm line 143. I see many people have had trouble with it so I moved on to something else like below. When I run this, I get "Undefined subroutine &main::ssh_cmd called at ./3test.pl line 3.". Net::SSH::Expect just seems to be overkill for something this simple. Can someone give me a hand on this?
Thank you.
#!/usr/bin/perl use Net::SSH qw(ssh issh sshopen2 sshopen3); ssh_cmd ({ user => 'root', host => '192.168.1.2', command => "chmod 777 /var/named/zzz.z", args => ["-i /root/.ssh/thispc-ssh-key", "-P 33"], stdin_string => "string\n", });

Replies are listed 'Best First'.
Re: Run Remote Command Via SSH
by Sandy (Curate) on Nov 06, 2012 at 00:44 UTC
    Hi, sorry, I know nothing about Net::SSH.

    However, when you "use" with a list, it is only subs within that list that are immediately available.

    Try

    use Net::SSH qw(ssh_cmd ssh ...)

    Good luck!

      I just sent an email to the module authors since the code posted by the OP is almost straight out of the synopsis for Net::SSH. The example code also does not import ssh_cmd. It's minor but can be confusing for someone new to Perl.

Re: Run Remote Command Via SSH
by salva (Canon) on Nov 06, 2012 at 09:11 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-23 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found