Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Problem to connect remote host

by perladdict (Chaplain)
on Apr 09, 2007 at 14:32 UTC ( #608969=perlquestion: print w/ replies, xml ) Need Help??
perladdict has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,
I am trying to logon to remote host by using Net::SSH,if the login succeeds means,
i have to ping the ip of this machine to know the status of the server.
Actualy my task is to ping the machine and find the satus and i have to find the diskspace usage as well as cpu usage

as i know we can do this by using system command and as well as Net::Telnet module.
I don't want to hardcode username and passward,bcz of that i am using Net::SSH
module,can any body help me out to find where i am doing mistake.

#!/usr/bin/perl -w use Net::SSH::Perl; my $ssh = Net::SSH::Perl->new ("$hostname"); $ssh->login("xxxx","xxxx"); my($stdout, $stderr, $exit) = $ssh->cmd(" hostname"); print "$stdout\n";
after trying the above code i am getting error as below
Undefined subroutine &main::login called at ssh.txt line 6.

Comment on Problem to connect remote host
Download Code
Re: Problem to connect remote host
by ikegami (Pope) on Apr 09, 2007 at 14:41 UTC
    Are you sure that code that gave that error? Aside from the lack of anything related to login on line 6, I can't see that code giving that particular error. (I would expect <<Can't call method "login" on an undefined value>> or <<Can't locate object method "login" via package "XXX">> if anything.) That error would occur if the $ssh-> in $ssh->login was missing.
Re: Problem to connect remote host
by ptum (Priest) on Apr 09, 2007 at 14:42 UTC

    So, um, which module are you using? There seems to be some confusion between your code and your question. Net::SSH is not the same as Net::SSH::Perl. Are you sure you have Net::SSH::Perl installed on your system in a library where it can be found?

Re: Problem to connect remote host
by shmem (Canon) on Apr 09, 2007 at 14:52 UTC
    Is that code snippet the one you are running? I doubt it, since
    • you would get the error Undefined subroutine &main::login had you called 'login' as a function:
      login("xxxx","xxxx");

      If your $ssh object was undefined, you would get the error

      Can't call method "login" on an undefined value
    • the call to the login method occurs at line 4, not line 6
    • since you haven't defined $hostname you ought to get the error:
      Net::SSH: Bad host name: at foo.pl line 3

    Furthermore, it's a good idea to ping the machine first, and then attempt to ssh into it.

    Last but not least don't double-quote single variables as in the useless interpolation

    Net::SSH::Perl->new ("$hostname");

    Say rather

    Net::SSH::Perl->new ($hostname);

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Problem to connect remote host
by McDarren (Abbot) on Apr 09, 2007 at 14:59 UTC
    "Actualy my task is to ping the machine and find the satus and i have to find the diskspace usage as well as cpu usage"

    Sounds to me like you need a Network Monitoring System. Before you go off and re-invent the wheel, you might want to check out a few off-the-shelf (and Open Source) products that do exactly what you need. A few recommended ones might be Nagios, Big Brother, and Big Sister. But there are plenty more to choose from.

    Cheers,
    Darren :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2014-11-28 03:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (192 votes), past polls