- my $connected= `ipsec whack --status | grep $remoteip`;
- my $established= `ipsec whack --status | grep '$settings[2]' | grep 'ISAKMP SA established'`;
-
- if ( $established eq '' || $connected eq '' ){
- logger("Remote IP for host $remotehostname has changed or no connection is established, restarting connection to $remoteip.");
+ my $ipmatch= `echo "$status" | grep '$remoteip' | grep '$settings[2]'`;
+ my $established= `echo "$status" | grep '$settings[2]' | grep -e 'erouted;' -e 'INSTALLED'`;
+ my $known= `echo "$status" | grep '$settings[2]'`;
+
+ if ( $ipmatch eq '' && $known ne '' ){
+ logger("Remote IP for host $remotehostname($remoteip) has changed, restarting ipsec.");