Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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 ~ ~ ~ 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 ./ 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 => '', 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
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.


    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 (Abbot) on Nov 06, 2012 at 09:11 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1002404]
Approved by Sandy
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: (12)
As of 2015-10-07 13:49 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (186 votes), past polls