zoukankan      html  css  js  c++  java
  • 批量分发密钥脚本(判断存活IP和自动搭建本地yum和云yum仓库)

    批量分发密钥脚本

     
    1. #!/bin/bash
    2. function xxx(){   #云yum函数
    3. ping -c 1 www.baidu.com
    4. if [ $? -eq 0 ];then
    5. rpm -qa | grep "wget"
    6. if [ $? -ne 0 ];then
    7. yum -y install wget &> /dev/null || (yum && yum -y install wget) || exit
    8. echo "wget安装成功"
    9. fi
    10. fi
    11. cd /etc/yum.repos.d/ && [ -d bak ] || mkdir bak
    12. mv C* bak
    13. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo &> /dev/null
    14. yum -y clean all &> /dev/null
    15. yum makecache &> /dev/null
    16. }
    17. function yyy(){   #本地yum函数
    18. [ -d /media/cdrom ] || mkdir -p /media/cdrom
    19. umount /dev/sr0 &>/dev/null
    20. mount /dev/sr0 /media/cdrom &>/dev/null
    21. if [ $? -eq 0 ] ;then
    22. echo "光盘已挂载"
    23. else
    24. echo "请检查光盘"
    25. exit
    26. fi
    27. cd /etc/yum.repos.d
    28. mv * /tmp
    29. cat > /etc/yum.repos.d/local.repo << OK
    30. [local]
    31. name=local
    32. baseurl=file:///media/cdrom
    33. gpgcheck=0
    34. enabled=1
    35. OK
    36. yum -y clean all &>/dev/null
    37. yum makecache &>/dev/null && echo "光盘yum搭建完成"
    38. }
    39. rpm -qa | grep "sshpass" &>/dev/null   #检测有没有sshpass命令
    40. if [ $? -ne 0 ];then
    41. yum -y install sshpass &>/dev/null || (xxx && yum -y install sshpass) || exit 3
    42. fi
    43. rpm -qa | grep "openssh-clients" &>/dev/null
    44. if [ $? -ne 0 ];then
    45. yum -y install openssh-clients &>/dev/null || (yyy && yum -y install openssh-clients) || exit 5
    46. fi
    47. cd ~
    48. [ -d .ssh ] && rm -rf ~/.ssh/id_dsa* || mkdir .ssh
    49. chmod 700 .ssh
    50. ssh-keygen -t dsa -f ~/.ssh/id_dsa -P "" &>/dev/null
    51. i=1
    52. for ip in 192.168.200.{67..100}   #判断存活IP,IP段可随意修改
    53. do
    54. ping -c 1 -i 0.1 $ip &>/dev/null
    55. if [ $? -eq 0 ];then
    56. sshpass -p "linyaonie" ssh-copy-id -i ~/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no $ip" &>/dev/null
    57. let i++
    58. echo "$ip密钥分发成功"
    59. else
    60. echo "$ip无法ping通请检查网络"
    61. fi
    62. done
  • 相关阅读:
    设计模式
    mysql引擎与物理文件
    org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'socialCode' in 'class java.lang.String'
    bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
    jedis异常Broken pipe (Write failed)
    java第三方工具包
    mysql安装(centos7)
    sftp安装(linux)
    Snmp oid对应信息
    RAID
  • 原文地址:https://www.cnblogs.com/linyaonie/p/9911391.html
Copyright © 2011-2022 走看看