Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Run Remote Command Via SSH

by Anonymous Monk
on Nov 06, 2012 at 00:34 UTC ( #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", });

Comment on Run Remote Command Via SSH
Download Code
Re: Run Remote Command Via SSH
by Sandy (Deacon) 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 (Monsignor) on Nov 06, 2012 at 09:11 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
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? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2014-07-26 06:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls