分类: 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