Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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", });

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
[shmem]: just one proverb before dozing off: when dealing with a bear, hubris is suicidal
[shmem]: Old_Gray_Bear would nod, and go back to sleep, then - but he's been sleeping for a year now.
[erix]: "AngloZionist Empire"? "Stop the Empire's war on Russia?" WTF?
erix stops reading as recommended by the blog itself
[erix]: my attention being jealously guarded ;)
[shmem]: erix, yes, it's a WTF. Since...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2018-03-19 20:49 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (246 votes). Check out past polls.