expect 脚本的奇怪的运行
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 呢。这个该怎么改啊。。。。求大侠帮帮忙啊
[解决办法]
把kill -9 `ps -ef|grep "cu -l "|head -1|awk '{print $1}'`里面的"和$都转义下先。