- 论坛徽章:
- 0
|
- #!/usr/bin/expect -f
- set f [open $PWD/ip.txt r]
- for {} {gets $f ipaddr } {} {
- set ip [lindex ipaddr 1]
- set pwd [lindex ipaddr 2]
- ssh -p22 root@$ip
- expect {
- "ssh: Could not resolve hostname : Name or service not known" {send_user "[exec echo \" ssh: Could not resolve hostname\($s
- ip\) : Name or service not known\" >>config_log]";exit}
- "not know" {send_user "[exec echo \"not know:$localip\" >>config_log]";exit}
- "(yes/no)?" {send "yes\r";exp_continue}
- "password:" {send "$pwd\r";exp_continue}
- "Permission denied, please try again." {
- send_user "[exec echo \"Error:Password is wrong:$localip\">>config_log]"
- exit
- }
-
- }
- expect " ~]#" {send "you command\r"}
- expect "]$ " {send "you command\r"}
- close
- }
- close $f
复制代码
脚本从ip.txt文件中读取ip地址和登录密码,格式如下
192.168.1.1 123456
192.168.1.1 234567
如果登录时候的部分错误会记录在config_log里,由于没有环境,暂时没有测试。。大概的过程就是这个样子。 |
|