Chinaunix首页 | 论坛 | 博客
  • 博客访问: 10479704
  • 博文数量: 2905
  • 博客积分: 20098
  • 博客等级: 上将
  • 技术积分: 36298
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-23 05:00
文章存档

2012年(1)

2011年(3)

2009年(2901)

分类: LINUX

2009-03-23 10:49:41

#!/usr/bin/expect -f

set ipaddress [lindex $argv 0]
set passwd [lindex $argv 1]
set timeout 30
spawn ssh root@$ipaddress

#expect "yes/no"
#send "yes\r"

expect "password:"
send "$passwd\r"
expect "]*"
send "mkdir -p /tmp/haha/haha2\r"
send "exit\r"
 
***************
expect {
"(yes/no)?" {
     send "yes\n"
  }
"password:" {
   ....
}




判断语句

if {$havepass == 0} {
  expect "password:" { send "$pw\n" }
}
 
或者:
 
expect {
"yes/no" { send "yes\r"; exp_continue}
"password:" { send "$passwd\r" }
}
阅读(976) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~