免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2419 | 回复: 8
打印 上一主题 下一主题

双线自动切换脚本无法运行.大家帮忙看下了. [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-07-05 11:31 |只看该作者 |倒序浏览
[root@localhost 111]# ls  运行坏境为FC4. /expect 已经安装成功.
fw  netwatch.exp
[root@localhost 111]# ./fw
./fw: line 4: netwatch.exp: command not found
./fw: line 6: netwatch.exp: command not found
./fw: line 12: syntax error near unexpected token `do'
./fw: line 12: `       do some recovery action here ...'
[root@localhost 111]#

netwatch.exp脚本内容
#!/usr/bin/expect

set target [lindex $argv 0]
set timeout 1
spawn ping -c 1 -s 1 $target

expect {
    " 0% packet loss" {
        exit 0
    }
    timeout {
        exit 1
    }
}

fw脚本内容

#!/bin/sh

netwatch.exp 192.168.1.1
result1=$?
netwatch.exp 192.168.2.1
result2=$?
if [ "$result1" eq 0 ] && [ "$result2" eq 0 ] ; then

# 如果上次检测时连接丢失,而此次恢复正常
    if [ -e /var/run/lost-connection ] ; then
       do some recovery action here ...
       rm /var/run/lost-connection
    fi

# 如果网关1不可达
elif [ "$result1" ne 0 ] ; then
   change default route to 192.168.2.1
   do some action here, such as iptables NAT

   # 创建连接丢失标识
   touch /var/run/lost-connection

# 如果网关2不可达
elif [ "$result2" ne 0 ] ; then
   change default route to 192.168.1.1
   do some action here, such as iptables NAT

   # 创建连接丢失标识
   touch /var/run/lost-connection
fi


参考贴:http://bbs.chinaunix.net/viewthread.php?tid=672561
希望高人帮我看看了.

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
2 [报告]
发表于 2006-07-05 11:36 |只看该作者
./netwatch.exp
或者把netwatch.exp所在目录加入路径

do那个错误不用讲了吧?

论坛徽章:
0
3 [报告]
发表于 2006-07-05 11:59 |只看该作者
你还是讲下吧..小弟不懂SHELL啊.
谢谢"他爹"了.

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
4 [报告]
发表于 2006-07-05 12:04 |只看该作者
去英文版问吧?或者找个软件翻译一下

论坛徽章:
0
5 [报告]
发表于 2006-07-05 12:32 |只看该作者
噢..谢谢.

论坛徽章:
0
6 [报告]
发表于 2006-07-05 16:16 |只看该作者
再帮我看下了.
执行后又出错了.
spawn ping -c 1 -s 1 192.168.100.1
PING 192.168.100.1 (192.168.100.1) 1(29) bytes of data.
9 bytes from 192.168.100.1: icmp_seq=0 ttl=128

--- 192.168.100.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
spawn ping -c 1 -s 1 192.168.10.1
PING 192.168.10.1 (192.168.10.1) 1(29) bytes of data.
./fw: line 7: [: eq: binary operator expected
./fw: line 18: [: ne: binary operator expected
./fw: line 21: [: ne: binary operator expected


fw的脚本如下:
#!/bin/sh
/111/netwatch.exp 192.168.100.1
result1=$?
/111/netwatch.exp 192.168.10.1
result2=$?

if [ "$result1" eq 0 ] && [ "$result2" eq 0 ]
then

# ...................
    if [ -e /var/run/lost-connection ]
    then
       rm /var/run/lost-connection
    fi



elif [ "$result1" ne 0 ]
then
        /sbin/ip  route replace via 192.168.10.1 dev eth1
elif [ "$result2" ne 0 ]
then
        /sbin/ip  route replace via 192.168.100.1 dev eth1 talbe 100
else
        echo "yy"

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
7 [报告]
发表于 2006-07-05 16:21 |只看该作者
-eq
-ne

看新手导航吧?省点时间

论坛徽章:
0
8 [报告]
发表于 2006-07-05 16:28 |只看该作者
大哥.你帮我改下啊.
我急用啊.

论坛徽章:
0
9 [报告]
发表于 2006-07-05 17:02 |只看该作者
int1 -eq int2    两数相等为真
    int1 -ne int2    两数不等为真
    int1 -gt int2    int1大于int2为真
    int1 -ge int2    int1大于等于int2为真
    int1 -lt int2    int1小于int2为真
    int1 -le int2    int1小于等于int2为真

老大.谢谢你..我找到了.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP