免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: chenshouqi2003
打印 上一主题 下一主题

[服务应用] linux小脚本编写 [复制链接]

论坛徽章:
2
午马
日期:2015-01-27 11:22:392015年辞旧岁徽章
日期:2015-03-03 16:54:15
11 [报告]
发表于 2012-07-09 14:27 |只看该作者
回复 10# chenshouqi2003


    什么操作系统?

   试下命令 which expect

论坛徽章:
0
12 [报告]
发表于 2012-07-09 14:29 |只看该作者
回复 11# to407
centos 5.5 系统
/usr/bin/which: no expect in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)这是which出来的
   

论坛徽章:
2
午马
日期:2015-01-27 11:22:392015年辞旧岁徽章
日期:2015-03-03 16:54:15
13 [报告]
发表于 2012-07-09 14:36 |只看该作者
回复 12# chenshouqi2003


安装expect包。。。

如果是64位选这个

    ftp://ftp.muug.mb.ca/mirror/cent ... .0-8.el5.x86_64.rpm

32位选这个
  
   ftp://ftp.muug.mb.ca/mirror/cent ... 43.0-8.el5.i386.rpm

装好了再跑一遍脚本就ok了

论坛徽章:
0
14 [报告]
发表于 2012-07-09 14:36 |只看该作者
回复 11# to407
原来是没装expect  现在安装了。执行脚本提示-bash: spawn: command not found
couldn't read file "Escape character is '^]'.": no such file or directory
-bash: send: command not found
couldn't read file "ok": no such file or directory
-bash: send: command not found



   

论坛徽章:
0
15 [报告]
发表于 2012-07-09 14:41 |只看该作者
回复 13# to407
[root@localhost shdir]# which expect
/usr/bin/expect

[root@localhost shdir]# . 1.sh
-bash: spawn: command not found
couldn't read file "Escape character is '^]'.": no such file or directory
-bash: send: command not found
couldn't read file "ok": no such file or directory
-bash: send: command not found

[root@localhost shdir]# vim 1.sh
#!/usr/bin/expect
spawn /usr/bin/telnet 127.0.0.1 11211
expect "Escape character is '^]'."
send "flush_all"
expect "ok"
send "quit"
~           

   

论坛徽章:
2
午马
日期:2015-01-27 11:22:392015年辞旧岁徽章
日期:2015-03-03 16:54:15
16 [报告]
发表于 2012-07-09 14:43 |只看该作者
回复 15# chenshouqi2003


    expect 1.sh

或者
   
   ./1.sh

来运行

话说。。。你知道 . 1.sh是在做什么呢。。。

论坛徽章:
0
17 [报告]
发表于 2012-07-09 14:48 |只看该作者
回复 16# to407
我知道错了。。谢谢啊。。一万分感谢。以前随手写的东西都是. XXX.sh 来执行的


   

论坛徽章:
2
午马
日期:2015-01-27 11:22:392015年辞旧岁徽章
日期:2015-03-03 16:54:15
18 [报告]
发表于 2012-07-09 14:49 |只看该作者
回复 17# chenshouqi2003


    用 . 或者 source 运行脚本 会改变当前session的状态和环境变量, 不推荐~~~ 建议随手放一本shell脚本的参考书翻翻。

论坛徽章:
0
19
发表于 2012-07-09 14:50
回复 16# to407



    [root@localhost shdir]# expect 1.sh
spawn /usr/bin/telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
flush_all[root@localhost shdir]#
现在这样 是正常的吗?

论坛徽章:
2
午马
日期:2015-01-27 11:22:392015年辞旧岁徽章
日期:2015-03-03 16:54:15
20 [报告]
发表于 2012-07-09 14:52 |只看该作者
回复 19# chenshouqi2003


    正常。。。虽然我不晓得你的flush_all 是在做什么。。。

    而且也没有你所说的 "ok" 输出
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP