Fellow monks,
I am calling on your wisdom in search for some advice. I have this code that gets names from a mysql database and uses the name to get a mac address via rsh. The server executing this script is a linux machine. the hosts i am connecting to are NT/2k machines. Some of the machines on my list are behind seperate firewalls. So when my script hits a machine like this, it hangs waiting for a response.
Is there a way to set a default timeout value, like say 20 secs, to wait for a response before it goes on to the next machine. Any advice would be greatly appreciated. Here is my code:
#!/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; }
thanks, Ray

edited: Thu Jan 2 05:06:23 2003 by jeffa - added <readmore>


In reply to can i set a timeout by MulletRay

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.