Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl script for inventory collection for large server estate 1

Status
Not open for further replies.

sm42

Technical User
Dec 11, 2003
133
GB
Hello

I'm new to Perl.
Have read many perl materials/books/web over some time now.

Just cant get into it!
Not the easiest of subjects to learn, programming that is.

So I have given my self a task to do, to make learning easier/interesting.

I'd like to write or reuse Perl code already out there that:
can be executed from a golden host
which collects basic info about servers (using ssh or telnet)
such as os version, output of various solaris commands
Then I'd like the perl script to keep this info or maybe upload to a data base...

I'm sure someone has already done this using perl.
if not can someone point me in the right direction in order to do this?

this may be asking too much.. but any help or guidelines would be appreciated

Thanks in advance.
 
The first place to look for anything you think has been done before is CPAN ( )
At the least, you can install the Net::Telnet module (or Net::SSH::perl) and fire off commands to each server and capture the output. To store the data in a database, you can use the DBI module.


Almost all modules will have examples in the documentation to get you started.

For your program, I'd start by:
1. create an array of server IPs
2. loop through the array and connect to each server
3. submit commands, capture output
4. Start by writing results to STDOUT, then work on updating a text file or database.


This is one way to loop through an array in perl:
Code:
#!/usr/bin/perl   # or whereever the perl binary is on your system (not really needed on windows)
use strict;       # always use strict!
use warnings;     # helpful but not mandatory

my @servers = ('172.12.42.91', '172.12.42.92', '172.12.42.93');

foreach my $server_ip (@servers) {

    print $server_ip , "\n";

}

Once you get that working, add the telnet or ssh module, and put the code to connect inside the loop (connecting to $server_ip each time). If you want to go further with it, try putting the telnet and database code into subroutines.

Get familiar with perldoc (the documentation included with perl) everything you need to know is in there. Browse the FAQs and perlfunc to see what kind of things you can do. It took me a while to get used to the documentation especially since perl was pretty much my first prog. language. I had the same experience as you when I started.. I didn't really get anywhere with perl until I had a real world problem to solve.

I'm not sure if you have experience with any other languages, so.. sorry if some of this seems a bit basic. :)
 
thanks for the reply, did not think anyone would reply given my inexperience within perl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top