perl module for getting information from remote machines
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
...
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.
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
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:
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.
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.