The below script has been working well for over a year, but 3 weeks ago something changed on the networks side which is now causing the script fail due to network timeouts. Can anyone suggest a way to make this script more robust?
#!/usr/bin/perl # SNMP reset tool #use strict; $SIG{PIPE} = sub { print "Ignoring SIGPIPE\n"; }; chdir("/home/ossutils/snmpreset"); #Read arguments $input = @ARGV[0]; #set up report file $result = `date '+%Y%d%m%H%M%S'`; chomp($result); $result = "snmpreset-$result.log"; open(REPORT, ">>$result"); #Open sockets use IO::Socket; #get last log file @lsout = `ls -1tr /u01/appl/bea/logs/log01_*`; print "DONE FIRST LIST\n"; $cnt = scalar(@lsout); $inlog = (@lsout[($cnt - 1)]); open(INPUT, "$inlog"); print "start init read\n"; while (<INPUT>) {;} INPUT -> clearerr(); print "done with initial read\n"; print "start endless look\n"; for (;;) { while (<INPUT>) { if ($_ =~ m/Reboot Device with MAC address/) { $mac = $_; $mac =~ s/^.*address: //g; $mac =~ s/ Thread.*//g; $mac1 = $mac; $sock = new IO::Socket::INET( PeerAddr => 'IP1', PeerPort => '5000', Proto => 'tcp', ); $sock1 = new IO::Socket::INET( PeerAddr => 'IP2', PeerPort => '5555', Proto => 'tcp', ); $sock or next; #or print "no socket :$!"; print $sock "$mac"; print $sock1 "$mac1"; close $sock; close $sock1; $tm = `date '+%Y%d%m%H%M%S'`; chomp($tm); chomp($mac); chomp($mac1); print REPORT "$tm - $mac reset request sent\n" +; print REPORT "$tm - $mac1 reset request sent\n +"; } } @lsout = `ls -1tr /u01/appl/bea/logs/log01_*`; $cnt = scalar(@lsout); $inlogb = (@lsout[($cnt - 1)]); if ($inlog ne $inlogb) { close(INPUT); open(INPUT, "$inlogb"); $inlog = $inlogb; } INPUT -> clearerr(); } print "Terminating incorrectly\n"; close(INPUT); close(REPORT); exit;
Thanks :)

In reply to session expiry by trelane

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.