我在想,b/c有时ping会起作用,但那只是b/c而已。ICMP,但当真正的流量试图通过隧道时,它不工作,b/c有2-3个隧道。我想做一个IF $tunnels >1和$tunnels == 0来做下面的重启IPSec的操作。
没那么容易
#!/bin/bash
echo begin ping
ping -c 3 -w 3 -t 2 192.168.1.4 &> /dev/null ;
service ipsec status | awk 'NR==3' | cut -d" " -f1 $tunnels
if
[ $? == 0 ]
then
echo "Connection is up" >> /root/restart_ipsec.log
else
echo "Connection is down" >> /root/restart_ipsec.log
date >> /root/restart_ipsec.log;
/sbin/service crond stop >> /root/restart_ipsec.log;
/sbin/service ipsec stop >> /root/restart_ipsec.log;
sleep 120;
/sbin/service ipsec start >> /root/restart_ipsec.log;
/sbin/service crond start >> /root/restart_ipsec.log;
fi我试过了,但它一直在使用第一个。即使我说隧道的数量大于1或0,它仍然使用该语句。怎么回事!?
tunnels=$(service ipsec status | awk 'NR==3' | cut -d" " -f1 | sed -e 's/^[ ]*//')
a=0
if
(( $tunnels > $a));
then
echo "To many tunnels =" $tunnels >> /root/restart_ipsec2.log;
echo $a;
elif
[ $tunnels == 0 ]
then
echo "To many tunnelss =" $tunnels >> /root/restart_ipsec2.log
elif
echo "luis3";
[ $? == 0 ]
then
echo "Connection is up" >> /root/restart_ipsec2.log
else
echo "Connection is down" >> /root/restart_ipsec2.log
fi发布于 2013-07-29 22:56:08
尝试使用[ $? -eq 0 ],因为它是一个数字比较。
另外,这一行:
service ipsec status | awk 'NR==3' | cut -d" " -f1 $tunnels没有多大意义。如果您希望它打印第一个字段,则执行以下操作:
service ipsec status | awk 'NR==3{print $1}'我不知道的是$tunnels在你的产品线中的用法。
https://stackoverflow.com/questions/17927244
复制相似问题