Chinaunix首页 | 论坛 | 博客
  • 博客访问: 521417
  • 博文数量: 102
  • 博客积分: 950
  • 博客等级: 准尉
  • 技术积分: 1094
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-28 16:07
文章分类

全部博文(102)

文章存档

2020年(2)

2016年(5)

2015年(15)

2014年(25)

2013年(18)

2012年(19)

2011年(18)

我的朋友

分类: LINUX

2016-02-18 12:36:58

#!/bin/bash

if [ $# -eq 2 ]; then
        user="$1"
        ip="$2"
else
        echo "Usage: $0 username ip"
        exit
fi
#user='root'
#ip='localhost'
password='xitongbu'

expect -c "
           set timeout 1;
           spawn ssh -p 22  ;
           expect {
               yes/no { send \"yes\r\"; exp_continue }
               *assword* { send \"$password\r\" }
           } ;
           expect $user@*   {send \" ls -l \r\" }  ;
           expect $user@*  { send exit\r } ;
           expect eof ;
       "

==========================
#!/usr/bin/expect  -d 


#set timeout 5


set PASSWD  [lindex $argv 0]
set HOST [lindex $argv 1]




spawn ssh-copy-id    $HOST
expect {
        "machine" {}
        *(yes/no)* {send "yes\r"; exp_continue;}
        *password* {send "${PASSWD}\r"; exp_continue;}
}


expect eof
exit

阅读(1370) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~