去交互式
#!/usr/bin/expect
set IP [lindex $argv 0]
set PASSWORD 123123
set timeout 10
spawn ssh-copy-id root@$IP
expect {
"yes/no" {send "yes\r";exp_continue}
"password:" {send "$PASSWORD\r"}
}
interact
批量分发密钥
#!/bin/bash
#
. /etc/init.d/functions
/usr/bin/rpm -qa | grep expect &> /dev/null
if [ $? -ne 0 ]; then
echo "正在安装expect程序......"
yum -y install expect &> /dev/null
fi
for I in {151..154}
do
/root/去交互式.sh 192.168.100.$I &> /dev/null
if [ $? -eq 0 ]; then
action "执行192.168.100.$I" /bin/true
else
action "执行192.168.100.$I" /bin/false
fi
done
批量分发与管理
#!/bin/bash
#
. /etc/init.d/functions
for I in {151..154}
do
#管理选项
#ssh root@192.168.100.$I $1 &> /dev/null
#分发选项
rsync -zavH $1 root@192.168.100.$I:/root/ &> /dev/null
if [ $? -eq 0 ]; then
action "执行192.168.100.$I" /bin/true
else
action "执行192.168.100.$I" /bin/false
fi
done