cc has asked for the wisdom of the Perl Monks concerning the following question:

hi

I have a vpn network with 2 redundant firewalls.
this perl script should look for the next hop and send a mail by unexpected redirect

#!/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";

how can I change it to delete routing cache,
before the ping command ?

kind regards
cc

Replies are listed 'Best First'.
Re: looking for the next hop
by leighsharpe (Monk) on Jan 24, 2006 at 05:54 UTC
    Better check the return value of this line:
    ip route flush cache
    If you are not logged in as root, you may not have access to he "ip" command. (either wrong permissions or wrong path.)
      no, I run this script from cron as root user
      and it seems to work,
      but I don't know if it's a good idea to feed the system with backticks.
      I would like to avoid zombie processes executed via perl.