Chinaunix首页 | 论坛 | 博客
  • 博客访问: 27828
  • 博文数量: 8
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 60
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-17 13:03
文章分类

全部博文(8)

文章存档

2013年(8)

我的朋友

分类: LINUX

2013-08-19 18:38:28


点击(此处)折叠或打开

  1. #!/bin/bash


  2. work_dir=/home/admin/
  3. cd $work_dir

  4. help (){
  5.         cat >> /dev/stdout << EOF
  6.         Example: ./$(basename $0)
  7. EOF
  8. }


  9. if [[ "$#" -ne 0 || "$1" == "-h" ]];then
  10.         help
  11.         exit 0
  12. fi

  13. jobmenu(){
  14.         PS3="Please select a Job name:"
  15.         select Job in "SystemLog_Collect" "DHCLIENT_SET" "NTP_SET" "Check_jobs" "Exit"
  16. do
  17.         case $Job in
  18.                 "Exit")
  19.                 echo "'Exit' selected. Script exits."
  20.                 exit 0
  21.                 ;;
  22.                 "")
  23.                 echo "=================================================================="
  24.                 error
  25.                 ;;
  26.                 "SystemLog_Collect")
  27.                 echo "'SystemLog_Collect' selected. Change seting ... "
  28.                 syslog
  29.                 modemenu
  30.                 ;;
  31.                 "Check_jobs")
  32.                 checkall
  33.                 modemenu
  34.                 ;;
  35.                 "DHCLIENT_SET")
  36.                 dhcp
  37.                 modemenu
  38.                 ;;
  39.                 "NTP_SET")
  40.                 ntp
  41.                 modemenu
  42.                 break
  43.                 ;;
  44.         esac
  45. done
  46. }

  47. Batch_jobmenu(){
  48.         if [ ! $ip_lst ]; then
  49.                 error
  50.                 echo "===============Back modemenu. Please select job mode=============="
  51.                 modemenu
  52.         fi
  53.         PS3="Please select a Job name:"
  54.         select Job in "SystemLog_Collect" "DHCLIENT_SET" "NTP_SET" "Check_jobs" "SUDOERS_check" "Exit"
  55. do
  56.         case $Job in
  57.                 "Exit")
  58.                 echo -e "\033[31m'Exit' selected. Script exits."
  59.                 exit 0
  60.                 ;;
  61.                 "")
  62.                 echo "=================================================================="
  63.                 error
  64.                 echo "===============Back modemenu. Please select job mode=============="
  65.                 modemenu
  66.                 ;;
  67.                 "SystemLog_Collect")
  68.                 echo "'SystemLog_Collect' selected. Change seting ... "
  69.                 for hostip in `cat $ip_lst`
  70.                 do
  71.                 syslog
  72.                 done
  73.                 echo "=========Done. Back modemenu. Please select job mode======="
  74.                 modemenu
  75.                 ;;
  76.                 "Check_jobs")
  77.                 for hostip in `cat $ip_lst`
  78.                 do
  79.                 checkall
  80.                 done
  81.                 echo "=========Done. Back modemenu. Please select job mode======="
  82.                 modemenu
  83.                 ;;
  84.                 "DHCLIENT_SET")
  85.                 for hostip in `cat $ip_lst`
  86.                 do
  87.                 dhcp
  88.                 done
  89.                 echo "=========Done. Back modemenu. Please select job mode======="
  90.                 modemenu
  91.                 ;;
  92.                 "NTP_SET")
  93.                 for hostip in `cat $ip_lst`
  94.                 do
  95.                 ntp
  96.                 done
  97.                 echo "=========Done. Back modemenu. Please select job mode======="
  98.                 modemenu
  99.                 break
  100.                 ;;
  101.                 "SUDOERS_check")
  102.                 for hostip in `cat $ip_lst`
  103.                 do
  104.                 sudoers_check
  105.                 done
  106.                 echo "=========Done. Back modemenu. Please select job mode======="
  107.                 modemenu
  108.                 break
  109.                 ;;
  110.         esac
  111. done
  112. }
  113. error(){
  114.         echo -e "\033[0;31;1m input error: \n please input again! \033[0m"
  115. }



  116. error(){
  117.         echo -e "\033[0;31;1m input error: \n please input again! \033[0m"
  118. }
  119. syslog(){

  120. cat >> syslog.cha.sh << EOF
  121. #!/bin/bash
  122. grep -q 192.168.33 /etc/syslog-ng/syslog-ng.conf || echo -e '###################################################################\n#Sending log to Syslog-ng relay option:\ndestination d_tcp { tcp("192.168.33.82" port(514)); };\nlog { source(src); destination(d_tcp); };\n' >> /etc/syslog-ng/syslog-ng.conf
  123. sed -i 's/3600/43200/' /etc/syslog-ng/syslog-ng.conf
  124. service syslog restart && echo -e "\033[0;32;1m ============ $hostip ============ Setting succuss! \033[0m" || echo -e "\033[0;31;1m ============ $hostip ============ Setting fail \033[0m"
  125. EOF

  126. scp syslog.cha.sh root@$hostip:/tmp/
  127. ssh root@$hostip "sh /tmp/syslog.cha.sh && rm -f /tmp/syslog.cha.sh"
  128. rm -f syslog.cha.sh
  129. }
  130. dhcp(){
  131.         ssh $hostip "sed -i '/DHCLIENT_SET_HOSTNAME/s/yes/no/g' /etc/sysconfig/network/dhcp;grep SET_HOSTNAME /etc/sysconfig/network/dhcp | grep -q no"
  132.                 case $? in
  133.                 0)
  134.                 echo -e "\033[0;32;1m ============ $hostip ============ DHCP Setting succuss! \033[0m"
  135.                 ;;
  136.                 *)
  137.                 echo -e "\033[0;31;1m ============ $hostip ============ DHCP Setting fail \033[0m "
  138.                 break
  139.                 ;;
  140.                 esac
  141. }

  142. ntp(){
  143.         ssh $hostip "grep -q '192.168.33.202' /etc/ntp.conf > /dev/null ||( cp /etc/ntp.conf /etc/ntp.conf.bak ; sed -e ' /fudge/a\server 192.168.33.201' -e '/fudge/a\server 192.168.33.202' /etc/ntp.conf.bak > /etc/ntp.conf;service ntp restart );pidof ntpd"
  144.                 case $? in
  145.                 0)
  146.                 echo -e "\033[0;32;1m ============ $hostip ============ NTP Setting succuss! \033[0m"
  147.                 ;;
  148.                 *)
  149.                 echo -e "\033[0;31;1m ============ $hostip ============ NTP Setting fail \033[0m "
  150.                 break
  151.                 ;;
  152.                 esac

  153.         }
  154. sudoers_check () {
  155.         echo -e " ============ $hostip ============"
  156.         ssh $hostip 'egrep -v "(^#|^$|Defaults)" /etc/sudoers'
  157. }

  158. checkall(){
  159.         echo "===========================$hostip============================="
  160.         ping -c 1 -q $hostip > /dev/null && ssh $hostip "echo -n 'Check $hostip syslog-ng config ...';grep -q '192.168.33.82' /etc/syslog-ng/syslog-ng.conf && echo -e '\033[0;32;1m OK \033[0m' || echo -e '\033[0;31;1m Fail \033[0m';echo -n 'Check $hostip DHCP config ...' ;grep 'DHCLIENT_SET_HOSTNAME' /etc/sysconfig/network/dhcp |grep -q 'no' && echo -e '\033[0;32;1m OK \033[0m' || echo -e '\033[0;31;1m Fail \033[0m'; echo -n 'Check $hostip NTP config ...';grep -q '192.168.33' /etc/ntp.conf && echo -e '\033[0;32;1m OK \033[0m' || echo -e '\033[0;31;1m Fail \033[0m';" || echo -e "$hostip \033[0;31;1m OFFLINE \033[0m "
  161.         echo -n "Check $hostip DNS record ..."
  162.         nslookup $hostip 192.168.33.1 |grep -q 'hwidc' && echo -e "\033[0;32;1m OK \033[0m" || echo -e "\033[0;31;1m Fail \033[0m"

  163. }
  164. modemenu(){
  165.         PS3="Please select a Job mode:"
  166.         select Job in "Batch Job" "Single Job" "Exit"
  167. do
  168.         case $Job in
  169.                 "Exit")
  170.                 echo "'Exit' selected. Script exits."
  171.                 exit 0
  172.                 ;;
  173.                 "")
  174.                 echo "=================================================================="
  175.                 error
  176.                 echo "=================================================================="
  177.                 modemenu
  178.                 ;;
  179.                 "Single Job")
  180.                 read -p "please input a ip address [Example: 10.0.0.1]" hostip
  181.                 jobmenu
  182.                 ;;
  183.                 "Batch Job")
  184.                 read -p "
  185. Example: host:~ # cat ip.lst
  186.                 10.0.0.1
  187.                 10.0.0.2
  188.                 10.0.0.3
  189. please input a file name [ip.lst]: " ip_lst
  190.                         if [ ! -f $ip_lst ]; then
  191.                         echo -e "\033[0;31;1m $(pwd)/$ip_lst No such file!!! Exit script \033[0m "
  192.                         exit
  193.                         fi
  194.                 Batch_jobmenu
  195.                 break
  196.                 ;;
  197.         esac
  198. done

  199. }

  200. modemenu


阅读(678) | 评论(0) | 转发(0) |
0

上一篇:python 增加用户

下一篇:收藏网址

给主人留下些什么吧!~~