- 论坛徽章:
- 0
|
set loginuser "root"
set ipaddr [lindex $argv 0]
set loginpass [lindex $argv 1]
set timeout 300
set cmd_prompt "]#|~]?"
#-------------------------------------------------- login by ssh
spawn ssh $loginuser@$ipaddr
set timeout 300
expect {
-re "Are you sure you want to continue connecting (yes/no)?" {
send "yes\r"
} -re "assword:" {
send "$loginpass\r"
} -re "Permission denied, please try again." {
exit
} -re "Connection refused" {
exit
} timeout {
exit
} eof {
send "echo'can not connect $ipaddr'>/root/error\r"
exit
}
}
expect {
-re "assword:" {
send "$loginpass\r"
}
-re $cmd_prompt {
send "\r"
}
}
#---------------------------------------------------- now,we do some commands
exec sleep 1
expect {
-re $cmd_prompt {
send "df -h\r"
}
}
#--------------------------------------------------
expect {
-re $cmd_prompt {
send "exit\r"
}
}
exit
#interact
本意就是想在批量对远程服务器进行执行脚本动作的时候,如果有密码不对的或者windows主机 等情况记录下来输入到本地机的一个文件里。
这个应该怎么写? |
|