免费注册 查看新帖 |

Chinaunix

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

为什么spawn不能执行,显示找不到spawn函数 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-10-10 10:45 |只看该作者 |倒序浏览
使用的shell--bash,源代码:

#!/bin/bash

spawn ftp -i -n 10.167.13.67
expect "*Name*"
send "xyz"
expect "*Password:*"
send "xyz"
expect "*successful*"
send "put /home/guyq/AVSEQ02.DAT AVSEQ022222.DAT"
expect "*OK*"
send "bye"

输出结果:
-bash :spawn:command not found
为什么spawn不能执行,显示找不到spawn函数呢?
是要有一些特殊的设置吗?请大家帮忙

论坛徽章:
0
2 [报告]
发表于 2004-10-10 11:24 |只看该作者

为什么spawn不能执行,显示找不到spawn函数

这个代码是expect的代码,
不由bash解释。
spawn可以看作expect脚本的内部函数。

第一行改成 #!/usr/bin/expect

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
3 [报告]
发表于 2004-10-10 11:40 |只看该作者

为什么spawn不能执行,显示找不到spawn函数

这是一个expect脚本,是需要用expect来解释的,就象perl,
首行一定要是#!/path/perl,python脚本,首行一定要是
#!/path/python

论坛徽章:
0
4 [报告]
发表于 2004-10-10 12:02 |只看该作者

为什么spawn不能执行,显示找不到spawn函数

第一行改成 #!/usr/bin/expect,问题解决!
谢谢各位了!你们的分析很精辟,简洁但不简单

论坛徽章:
0
5 [报告]
发表于 2013-06-03 14:47 |只看该作者
  1. $ which expect
  2. /usr/bin/expect
  3. $ ls -l /usr/bin/expect
  4. -rwxr-xr-x 1 root root 11792 Oct 17  2011 /usr/bin/expect
  5. $ cat test.sh
  6. #!/usr/bin/expect
  7. set timeout 5
  8. spawn ssh localhost "pwd"
  9. expect "password:"
  10. send "psop2000\r"
  11. interact
  12. $ sh test.sh
  13. test.sh: line 3: spawn: command not found
  14. couldn't read file "password:": no such file or directory
  15. test.sh: line 5: send: command not found
  16. test.sh: line 6: interact: command not found
复制代码
请帮忙看看谢谢

论坛徽章:
0
6 [报告]
发表于 2013-06-03 14:50 |只看该作者
$ rpm -qa |grep expect
expect-5.43.0-8.el5
pexpect-2.3-3.el5
expect-5.43.0-8.el5

论坛徽章:
0
7 [报告]
发表于 2013-06-03 14:54 |只看该作者
找到原因了。
含有expect的脚本不能用bash执行,bash无法解析。添加可执行权限后,直接./your_script即可。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP