expect,sshpass,pash
rpm -qa expect
yum install expect -y
useradd mohan
echo 123456|passwd –stdin mohan
su – mohan
ssh-keygen -t dsa -P ” -f ~/.ssh/id_dsa >/dev/null 2>&1
yum install lrzsz -y
cat mohan_sshkey.exp
#!/usr/bin/expect
if { $argc !=2 } {
send_user “usage: expect mohan_sshkey.exp file host\n”
exit
}
#define var
set file [lindex $argv 0]
set host [lindex $argv 1]
set password “123456”
#spawn scp /etc/hosts root@10.0.0.142:/etc/hosts
#spawn scp -P52113 $file testserver@$host:$dir
spawn ssh-copy-id -i $file “-p 22 oldgirl888@$host”
expect {
“yes/no” {send “yes\r” ;exp_continue}
“password” {send “$password\r”}
}
expect cof
exit -onexit {
send_user “testserver say good bye to you!\n”
}
#script usage
#expect testserver-6.exp file host dir
#example
#expect mohan_sshkey.exp file host dir
#expect mohan_sshkey.exp ~/etc/hosts 10.0.0.41:~
expect mohan_sshkey.exp .ssh/id_dsa.pub 192.168.1.21
#!/bin/sh
. /etc/init.d/functions
for ip in 8 31 41
do
expect mohan_sshkey.exp ~/.ssh/id_dsa.pub 192.168.1.$ip >/dev/null 2>&1
if [ $? -eq 0 ];then
action “$ip” /bin/true
else
action “$ip” /bin/false
fi
done
Recent Comments