-
批量分发密钥脚本(判断存活IP和自动搭建本地yum和云yum仓库)
批量分发密钥脚本
#!/bin/bash
function xxx(){ #云yum函数
ping -c 1 www.baidu.com
if [ $? -eq 0 ];then
rpm -qa | grep "wget"
if [ $? -ne 0 ];then
yum -y install wget &> /dev/null || (yum && yum -y install wget) || exit
echo "wget安装成功"
fi
fi
cd /etc/yum.repos.d/ && [ -d bak ] || mkdir bak
mv C* bak
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo &> /dev/null
yum -y clean all &> /dev/null
yum makecache &> /dev/null
}
function yyy(){ #本地yum函数
[ -d /media/cdrom ] || mkdir -p /media/cdrom
umount /dev/sr0 &>/dev/null
mount /dev/sr0 /media/cdrom &>/dev/null
if [ $? -eq 0 ] ;then
echo "光盘已挂载"
else
echo "请检查光盘"
exit
fi
cd /etc/yum.repos.d
mv * /tmp
cat > /etc/yum.repos.d/local.repo << OK
[local]
name=local
baseurl=file:///media/cdrom
gpgcheck=0
enabled=1
OK
yum -y clean all &>/dev/null
yum makecache &>/dev/null && echo "光盘yum搭建完成"
}
rpm -qa | grep "sshpass" &>/dev/null #检测有没有sshpass命令
if [ $? -ne 0 ];then
yum -y install sshpass &>/dev/null || (xxx && yum -y install sshpass) || exit 3
fi
rpm -qa | grep "openssh-clients" &>/dev/null
if [ $? -ne 0 ];then
yum -y install openssh-clients &>/dev/null || (yyy && yum -y install openssh-clients) || exit 5
fi
cd ~
[ -d .ssh ] && rm -rf ~/.ssh/id_dsa* || mkdir .ssh
chmod 700 .ssh
ssh-keygen -t dsa -f ~/.ssh/id_dsa -P "" &>/dev/null
i=1
for ip in 192.168.200.{67..100} #判断存活IP,IP段可随意修改
do
ping -c 1 -i 0.1 $ip &>/dev/null
if [ $? -eq 0 ];then
sshpass -p "linyaonie" ssh-copy-id -i ~/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no $ip" &>/dev/null
let i++
echo "$ip密钥分发成功"
else
echo "$ip无法ping通请检查网络"
fi
done
-
相关阅读:
js 跳转链接的几种方式
js 指定分隔符连接数组元素join()
Ajax async属性
非负数正则表达式
firefox因 HTTP 严格传输安全(HSTS)机制无法打开网页
查看linux系统某宏的定义(另类)
ctags高级用法
ctags简明用法
关于数组和指针的一道例题的解读
让gcc和gdb支持intel格式的汇编
-
原文地址:https://www.cnblogs.com/linyaonie/p/9911391.html
Copyright © 2020-2023
润新知