You could rearrange your script around it, to do something like this:


if [ "$action" = "stop" ]; then
echo "Clearing ipsec configuration.. "
$SK <<-EOF
flush;
spdflush;
EOF
exit
fi