cc has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use warnings; my $PingHost = '192.168.23.1'; my $ExpectedRedirect = '192.168.0.10'; my $MailTo = 'postmaster@domain.net'; my $ip = `ip route flush cache`; open( INPING, "ping -c 10 $PingHost|" ) || die "ping open failed"; while( my $line = <INPING> ) { next unless( $line =~ /Redirect Host\(New nexthop: (.*)\)/ ); next if( $1 eq $ExpectedRedirect ); open( OUTMAIL, "|mail -s 'VPN Unexpected Redirect: $1' $MailTo" ) | +| die "pipe to mail failed"; print OUTMAIL scalar localtime(); print OUTMAIL "\n\n"; print OUTMAIL "VPN NETWORK\n"; print OUTMAIL "Received an unexpected redirect to: $1\n"; close(OUTMAIL) || warn "bad pipe close"; } close(INPING) || warn "bad pipe close";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: looking for the next hop
by leighsharpe (Monk) on Jan 24, 2006 at 05:54 UTC | |
by cc (Beadle) on Jan 24, 2006 at 22:12 UTC |