以scp命令为例
[root@centos8 script]
rpm -q expect &> /dev/null || yum -y install expect > /dev/null
echo "本脚本主要用于C8向其他主机发送测试文件"
echo -e "\e[1;$[$RANDOM%7+31]m"
PS3="请选择将文件复制到哪 (1-6):"
select os in Centos8_154 Centos7_152 Centos6_153 Ubantu_151 C7+C6+U 选择完成,开始复制;do
case $REPLY in
1)
ip="10.0.0.154"
;;
2)
ip="10.0.0.152"
;;
3)
ip="10.0.0.153"
;;
4)
ip="10.0.0.151"
;;
5)
ip1="10.0.0.152"
ip2="10.0.0.153"
ip3="10.0.0.151"
;;
6)
echo "选择完成,开始复制"
break
;;
*)
echo "选择有误,请重新选择"
exit
;;
esac
done
echo -e "\e[0m"
user=root
passwd="xxxxxx"
for id in $ip $ip1 $ip2 $ip3;do
expect <<EOF
set timeout 20
spawn scp $1 $user@$id:/root/
expect {
"yes/no" { send "yes\n"; exp_continue }
"password" { send "$passwd\n" }
}
expect eof
EOF
done
|