#!/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 -> clearerr(); print "done with initial read\n"; print "start endless look\n"; for (;;) { while () { 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;