#!/usr/bin/perl -w ################################################################# # Ray Espinoza # # 12-31-02 # # GetMacsFromDB.pl - this script will get hostnames from # # our inventory database and query for # # the mac address and print it to a file. # ################################################################# use strict; use DBI; ###################################################### # create a database handle and defining my variables # ###################################################### my (@array_of_lines, $string, $mac); my $dbh = &connect; ########################################## # opening a pipe to my file to print out # ########################################## open (OUT,">>/home/respinoz/workbench/macs/MacResults.log") or die "Ca +n't open f ile: $!\n"; ########################################## # Calling the subroutine to do its work # ########################################## get_hostname_and_get_mac ($dbh); ############################################################## # All of the subs are named appropriately to their function # ############################################################## sub get_hostname_and_get_mac { my $dbh = shift; while (my $row = $sth->fetchrow_hashref()) { $hostname = $row->{name}; $mac = get_mac($hostname); print OUT "$hostname\t$mac\n"; } $sth->finish(); } ########### sub get_mac { my $hostname = shift; my ($string, $mac); $string = `/usr/bin/rsh $hostname nbtstat -a $hostname`; if ($string =~ /s*(([0-9A-Fa-f]{2}[-:]){5}[0-9A-Fa-f]{2})/) { $mac = $1; return $mac; } } ########### sub connect { my ($dbh, $sth, $count); $dbh= DBI->connect("DBI:mysql:host=localhost;database=testsites","xxxx +x","xxxxx" ,{PrintError => 0, RaiseError => 1}); return $dbh; }
edited: Thu Jan 2 05:06:23 2003 by jeffa - added <readmore>
In reply to can i set a timeout by MulletRay
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |