Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1364033
  • 博文数量: 704
  • 博客积分: 10140
  • 博客等级: 上将
  • 技术积分: 6230
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-15 20:41
文章分类

全部博文(704)

文章存档

2013年(1)

2012年(16)

2011年(536)

2010年(151)

分类:

2011-12-21 23:31:44

原文地址:能过SSH远程执行命令 作者:badb0y

其实就像我们执行ssh reboot一样,和和
#!/usr/bin/expect -f
if { $argc < 3 } {
puts stderr "Usage: $argv0 IPAdress Login OldPasswd"
exit
}
set IPADDR [lindex $argv 0]
set LOGIN [lindex $argv 1]
set OLD_PW [lindex $argv 2]
set timeout 30
stty -echo
spawn ssh $IPADDR -l $LOGIN
expect {
    "*assword:*"  {
        send "$OLD_PW\r"
        exp_continue
    } "*Last login:*" {
        #interact
        exit 0
    } timeout {
        send_user "connection to $IPADDR timeout!\n"
        exit 1
    } "*incorrect*" {
        send_user "password incorrect!\n"
        exit 2
    } "*Permission*" {  #for LINUX ssh
        send_user "password Error!\n"
        exit 2
    } eof {
        exit 3
    }
}
阅读(408) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~