#!/bin/bash SW="switch-catalyst-1 switch-catalyst-2 switch-catalyst-3 switch-catalyst-4 switch-catalyst-5 switch-catalyst-6 switch-catalyst-7 switch-nexus-1 switch-nexus-2 switch-nexus-3 switch-nexus-4" cd /scripts/rancid/stp_changes/ touch stp_changes3.lastrun for I in `echo $SW` do ./stp_changes2.sh $I | tr -d "\n\r" | perl -e ' # open file with switch stats from last run open FILE, "<.$ARGV[0]"; @FIL=; close FILE; # save values to oldres foreach (@FIL) { ($a,$b,$c,$d,$e) = split " ", $_; $oldres{"$a_$b"}=$c; } # open temp files for out from stp_changes2.sh open FILE, ">.tmp.$ARGV[0]"; $l=; $l=~s/MST/\nMST/g; @a=split "\n", $l; foreach (@a) { chomp; $sw = $ARGV[0]; if (/MST/) { # get new values from output ($m,$c,$o,$i) = $_ =~ m/MST([0-9]*) .* changes ([0-9]*) .* occurred (.*) ago .* from (.*)/; # if change number is higher than last time if ($oldres{"$sw_$m"} < $c) { $da=`date`; chomp $da; $url="http://10.99.0.99/port_configs.php\?hostname=" . $sw . "&ifname=" . $i; $d="config"; # $d soll port config anzeigen open OUT, ">>stp_changes3.log"; printf OUT "%-30s\tSTP change on switch %25s\tinstance %5d\tcount %5d\t%10s ago\tinterface %s\t%s\n", $da, $sw, $m, $c, $o, $i, $d; close OUT; } $oldres{"$sw_$m"}=$c; printf FILE "$sw $m $c $o $i\n"; } } close FILE; # if output of stp_changes2.sh is 0 let tmp file there to see that there has been a problem recently # otherwise save stats to switch file and remove temp one if ( -s ".tmp.$ARGV[0]" ) { `cp .tmp.$ARGV[0] .$ARGV[0]`; `rm .tmp.$ARGV[0]`; } ' $I done DAT=`date` tac stp_changes3.log | head -n 100 > stp_changes3.temp echo '' > stp_changes3.html echo '' >> stp_changes3.html echo "" >> stp_changes3.html cat stp_changes3.temp | sed "s/^/
/g" | sed "s/\t/<\/td>/g" | sed "s/$/<\/td><\/tr>/" >> stp_changes3.html echo "
" >> stp_changes3.html rm stp_changes3.temp