expect 脚本的奇怪的运行

yidubai 2012-07-18 10:39:04
1 #!/usr/bin/expect
2 set timeout 30
3 set kpn [lindex $argv 0]//删除进程号
4 set password "z\[\];',\./"
5 set port 3883
6 set host 192.168.0.172
7 set name root
8 #set password [lindex $argv 1]
9 spawn ssh -p $port $host -l $name
10 expect "*assword:\n"
11 send "$password\r"
12 expect eof
13 expect "#"
14 send "cu -l ttyS4\r"
15 expect " Connect."
16 send_user "initialition..."
17 send "atz\r"
18 expect "OK"
19 send "~!\r"
20 exec sleep 5
21 expect "#"
22 send "$kpn\r"/* 不知道为什么send "kill -9 `ps -ef|grep "cu -l "|head -1|awk '{print $1}'`"这样的代码会出错,就把它写在了s.sh中,然后加参数*/


运行结果是:
Connected.
initialition...
OK
~!ATH0
OK
AT+VCID=1
OK
AT+VCID=1
OK
s.sh
s.sh: command not found
cu: shell: Exit status 127
ATZ
OK
ATZ
OK
ATZ
OK
ATZ
OK


不知道为什么会不断的重复呢,还有我把代码的15行改为
expect {
"conncect." { exp_continue}
"*ttyS4*" { send_user "Line in use "; exit}
}
send_user "initialition..."
这样老师报找不到 "Connect" command 呢。这个该怎么改啊。。。。求大侠帮帮忙啊
...全文
83 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yidubai 2012-08-11
  • 打赏
  • 举报
回复
恩,好谢谢,这个问题我已经解决了,原来时expect兼容性问题
ace_fei 2012-07-20
  • 打赏
  • 举报
回复
12行的expect eof也没必要
ace_fei 2012-07-20
  • 打赏
  • 举报
回复
把kill -9 `ps -ef|grep "cu -l "|head -1|awk '{print $1}'`里面的"和$都转义下先。

37,742

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧