LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-16-2010, 05:44 AM   #1
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Rep: Reputation: 36
perl module for getting information from remote machines


Hi guys,

I need to get some information like cpu usage,free memory,swap memory and other information from a bunch of remote hosts.
Can any one tell me of a good perl module which does that.I dont want to use Net::Rsh or Net:SSH. Thanks.
 
Old 10-16-2010, 06:34 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by kdelover View Post
Hi guys,

... I dont want to use Net::Rsh or Net:SSH. Thanks.
Why ? And how do you expect to access the remote machines in the first place ?
 
Old 10-16-2010, 06:54 AM   #3
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Original Poster
Rep: Reputation: 36
Hi sergei,

I have used Net::Rsh earlier and the problem i have had is that,if i store a list of hosts in an array say @hosts=qw/host1 host2 host3 host4/; and if host2 is down then rsh fails to connect to host3 and host4 with an error:
Quote:
Invalid argument at rsh at line
and secondly if i use the Net::Rsh module i have to execute the script as root.

I believe if i have to use Net::Ssh i'd have to enable password less login for those hosts ( Currently we use rsh to connect to hosts with in the network with a password less login at my place of work).

I just wanted to know if there is any otehr alternative way :-)
Thanks
 
Old 10-16-2010, 07:09 AM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by kdelover View Post
...
I just wanted to know if there is any otehr alternative way :-)
Thanks
??? You need certain protocol for access. Or you can run a webserver on every remote machine and do what you need through the webserver.

'ssh' with passwordless login is a good idea.

I do not understand why you have to run Net::Rsh as 'root' - command line 'rsh' does not require 'root' privileges.

The host down problem is always a problem. I.e. you can't just access hosts in a loop - you need some kind of "background" process - through 'system' you would add '&' at the end of command, and without 'system' you'll need some kind of multithreading.
 
Old 10-16-2010, 07:31 AM   #5
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Original Poster
Rep: Reputation: 36
http://search.cpan.org/~riiki/Net-Rsh-0.02/Rsh.pm

It says
Quote:
Rsh protocol requires that the program be run as root or that the program be setuid to root
At the moment i ping the host first to see if its alive before i rsh.


Quote:
you need some kind of "background" process - through 'system' you would add '&' at the end of command, and without 'system' you'll need some kind of multithreading.
can you please explain what do you actually mean by this.thanks
 
Old 10-16-2010, 07:41 AM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by kdelover View Post
http://search.cpan.org/~riiki/Net-Rsh-0.02/Rsh.pm

It says

At the moment i ping the host first to see if its alive before i rsh.




can you please explain what do you actually mean by this.thanks
Strictly speaking, 'ping' is not sufficient because it is not atomic. I.e. a host can go down just after 'ping', but before the access through 'rsh', 'ssh'. But 'ping' is better than nothing.

Regarding '&' - in case of 'system' you do something like this:

Code:
system("ssh_command_producing_the_needed_output > needed_output.$hostname.txt &");
The point is that 'needed_output.txt' is on local machine. Since the job is in background, it doesn't block.

So, you launch these jobs per host and in, say, 10 seconds you check contents/size of 'needed_output.$hostname.txt' files - the empty ones mean stuck hosts. Remember, error messages go to stderr, and the needed output should go to stdout. You can capture stderr too in separate files per host.

Threads are executed in parallel - it's by definition, so a number of threads (one per remote host) is logically equivalent to the same number of background jobs per host.

Last edited by Sergei Steshenko; 10-16-2010 at 07:43 AM.
 
Old 10-16-2010, 11:14 AM   #8
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by kdelover View Post
Can any one tell me of a good perl module which does that.I dont want to use Net::Rsh or Net:SSH. Thanks.
Net::Telnet
 
Old 10-17-2010, 02:04 AM   #9
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Original Poster
Rep: Reputation: 36
thanks sergei and ghostdog.I am very new to the concept of threading in perl,i do not have much idea about it though.Can i use forking to do the same?
 
Old 10-17-2010, 02:18 AM   #10
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by kdelover View Post
thanks sergei and ghostdog.I am very new to the concept of threading in perl,i do not have much idea about it though.Can i use forking to do the same?
You can; the second group of links in http://www.linuxquestions.org/questi...1/#post4129472 uses 'fork' but wraps it threads, and it's a good thing. Remember, you also need shared variable for inter-thread/"thread" communications, so both true threads and the one implemented through 'fork' give you this facility. Just read the documentation patiently, it's not that hard, AFAIR there are code examples.
 
1 members found this post helpful.
Old 10-17-2010, 03:26 AM   #11
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by kdelover View Post
thanks sergei and ghostdog.I am very new to the concept of threading in perl,i do not have much idea about it though.Can i use forking to do the same?
Why do you even need threading at this stage. ? If you don't want to use Net::Rsh or Net::SSH, you can try Net::Telnet.
eg from doc
Code:
    use Net::Telnet ();
    $t = new Net::Telnet (Timeout => 10, Prompt => '/root\@linux/');
    $t->open("localhost");
    $t->login("user", "pass");
    @lines = $t->cmd("ps -eo pcpu,pid,user,args");
    print @lines;
    @lines = $t->cmd("free");
    print @lines;
    @lines = $t->cmd("iostat");
    print @lines;
    .....
 
Old 10-17-2010, 03:42 AM   #12
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Original Poster
Rep: Reputation: 36
hi ghostdog,

if were to extract information from say 200-300 hosts stored in an array and if loop over it,i guess that would take lot of time to do so.I think threading/forking should make this process relatively faster.
 
Old 10-17-2010, 04:03 AM   #13
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by kdelover View Post
hi ghostdog,

if were to extract information from say 200-300 hosts stored in an array and if loop over it,i guess that would take lot of time to do so.I think threading/forking should make this process relatively faster.
yes, i am not saying you can't use threading..I am just wondering why its your concern at the moment? You should be tackling how to get those information you want first. Then after that, threading.
 
Old 10-17-2010, 02:51 PM   #14
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by ghostdog74 View Post
Why do you even need threading at this stage. ? ...
Not to get stuck because of non-responding host. It's a typical problem. For example, I wrote a lot of job launching scripts executing jobs on various hosts from a given (and possibly dynamically changing) list, and stuck hosts are always a possibility/reality.
 
Old 10-17-2010, 07:07 PM   #15
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by Sergei Steshenko View Post
Not to get stuck because of non-responding host. It's a typical problem. For example, I wrote a lot of job launching scripts executing jobs on various hosts from a given (and possibly dynamically changing) list, and stuck hosts are always a possibility/reality.
He should not worry this stage yet. He won't be able to test out this threading stuff without writing the main information gathering code first.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving LinkStatus information of all Ports of switch using perl module net-SNMP satish kumar.t Linux - Networking 2 07-15-2010 09:54 AM
list perl module & install perl module DBD::mysql linson_85 Linux - Newbie 4 06-22-2009 10:42 AM
Perl module Compress::Zlib installed but perl not detecting it danran Programming 0 05-03-2007 01:50 PM
information from someone who routinely audits Windows and Linux machines studpenguin Linux - Security 35 07-02-2005 05:14 PM
Problem with perl module for w3c validator to work on my local Apache+PHP+perl instal tbamt Linux - Software 0 12-16-2004 05:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration