本帖最后由 cj2017 于 2016-9-6 06:08 编辑
1、非bash脚本,开头不能写成:
#!/bin/bash
应该根据whereis expect 的结果填写,如:
#!/usr/bin/expect
2、非bash脚本,运行时
不能写成: sh [脚本名]
应当给予可执行权限
./[脚本名]
====================================================
参考http://blog.csdn.net/zhuying_linux/article/details/6657020
另外需要注意的是:
不能按照习惯来用sh autosu.sh来这行expect的程序,会提示找不到命令,如下:
autosu.sh: line 3: spawn: command not found
couldn't read file "password:": no such file or directory
autosu.sh: line 5: send: command not found
autosu.sh: line 6: interact: command not found
因为expect用的不是bash所以会报错。执行的时候直接./autosu.sh就可以了。~切记!=====================================================================
1、非bash脚本,开头不能写成:
#!/bin/bash
应该根据whereis expect 的结果填写,如:
#!/usr/bin/expect
2、非bash脚本,运行时
不能写成: sh [脚本名]
应当给予可执行权限
./[脚本名]
====================================================
参考http://blog.csdn.net/zhuying_linux/article/details/6657020
另外需要注意的是:
不能按照习惯来用sh autosu.sh来这行expect的程序,会提示找不到命令,如下:
autosu.sh: line 3: spawn: command not found
couldn't read file "password:": no such file or directory
autosu.sh: line 5: send: command not found
autosu.sh: line 6: interact: command not found
因为expect用的不是bash所以会报错。执行的时候直接./autosu.sh就可以了。~切记!=====================================================================
interact 执行完成后保持交互状态,把控制权交给控制台,这个时候就可以手工操作了。如果没有这一句登录完成后会退出,而不是留在远程终端上。
expect eof 这个一定要加,与spawn对应表示捕获终端输出信息终止,类似于if....endif
expect eof 这个一定要加,与spawn对应表示捕获终端输出信息终止,类似于if....endif
expect脚本必须以interact或expect eof结束,执行自动化任务通常expect eof就够了。
编辑回复