免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1811 | 回复: 4

请教各位大牛分析遇到异常不能循环原因 [复制链接]

论坛徽章:
0
发表于 2011-05-18 09:33 |显示全部楼层
以下为写的一个通过跳板机远程登陆主机并执行多个命令的脚本,如果远程主机可以正常登陆则可以正常循环完成,如果说2.2.2.2不能登陆则脚本就退出不能跳过2.2.2.2登陆3.3.3.3主机了,请各位大牛分析是什么原因。谢谢。脚本如下:
#!/usr/bin/expect -d
set user [lindex $argv 0]
set sshhost [lindex $argv 1]
set pass [lindex $argv 2]
set code [lindex $argv 3]
set cmdfile [open [lindex $argv 4] ]
set timeout -1
spawn ssh [url=mailtouser@$sshhost]$user@$sshhost[/url]
match_max 100000
proc login { command } {
while { [gets $command c] >0 } {
send "$c\r";
}
seek $command 0 start
}
while {1==1} {
        expect {
                "'s password:" { send -- "$pass\r"; break; }
                "Are you sure you want to continue connecting \(yes\/no\)\? " { send -- "yes\r" }
        }
}
while {1==1} {
        expect {
                "*Enter PASSCODE:*" { send -- "$code\r"; break; }
                "*Permission denied.*" { puts "Wrong password"; exit }
        }
}
while {1==1} {
        expect {
                "*Access Denied*:" { puts "Your PASSCODE is wrong or RSA verify failed!"; exit }
                "*PASSCODE Accepted*" { puts "RSA verified  success!"; break; }
        }
}
foreach IP {
1.1.1.1
2.2.2.2
3.3.3.3
} {
        expect  "*server ip or domain name ( 'q' to exit ):*"
                send "$IP\r"
        expect  {
                "*password" { puts "you don't have the permission";continue }
                "*(yes/no)" { send "yes\r";continue }
                #"*permission denied*" { puts "$IP invalid or permission denied"; continue }
                "*permission denied*" {sleep 5; continue }
                timeout { continue }
                "$" {login $cmdfile; send "exit\r"; continue}
                   }
   }
close

论坛徽章:
0
发表于 2011-05-18 11:35 |显示全部楼层
没人知道吗???

论坛徽章:
0
发表于 2011-05-18 12:26 |显示全部楼层
自己多测试几回吧,看看把timeout时间设置成固定的值

论坛徽章:
0
发表于 2011-05-18 16:03 |显示全部楼层
exp_continue

论坛徽章:
0
发表于 2011-05-18 18:15 |显示全部楼层
还是不能解决。继续研究中
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP