- 论坛徽章:
- 0
|
本帖最后由 phelp1981 于 2011-08-22 19:05 编辑
求救,expect写的一个脚本,在执行过程中有两步不执行,就跳到后面的命令去了(在不执行的命令前有停顿,感觉肯定是有问题了)
即: sh get_info.sh scp
这两步没有执行。
附脚本。。请草帽大哥及各位高手帮忙看看啊。- #!/usr/bin/expect -f
- trap {
- set rows [stty rows]
- set cols [stty columns]
- stty rows $rows columns $cols < $spawn_out(slave,name)
- } WINCH
-
- set host [lrange $argv 0 0]
- set user [lrange $argv 1 1]
- set pass [lrange $argv 2 2]
- set localip 8.8.8.8
- set localuser root
- set localpass test
- set localpath root/getinfo
- set prompt "{#|$|>}"
- set timeout 20
- if { $argc < 3 } {
- puts "Usage: $argv0 host user pass\r"
- exit 1
- }
- spawn ssh -t $user@$host
- #match_max 100000
-
- expect "*?\(yes/no\)*" {
- send -- "yes\r"
- expect "*?assword:*"
- send -- "$pass\r"
- } "*?assword:*" {
- send -- "$pass\r"
- }
- expect -re $prompt {
- send -- "mkdir tempinfo\r"
- }
- expect -re $prompt {
- send -- "scp $localuser@$localip:/$localpath/get_info.sh /root\r"
-
- expect -re $prompt {
- send -- "scp $localuser@$localip:/$localpath/get_info.sh /root\r"
- expect "*?assword:*"
- send -- "$localpass\r"
- }
- expect -re $prompt {
- send -- "sh get_info.sh\r"
- }
- expect -re $prompt {
- send -- "scp /root/tempinfo/* $localuser@$localip:/$localpath\r"
- expect "*?assword:*"
- send -- "$localpass\r"
- }
- expect -re $prompt {
- send -- "rm get_info.sh\r"
- }
- expect -re $prompt {
- send -- "rm -r tempinfo\r"
- }
- expect -re $prompt {
- send -- "exit\r"
- }
- #exit 1
- expect eof
复制代码 |
|