Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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
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.


    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?

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 making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2014-09-21 14:39 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (172 votes), past polls