Mu class Network Shell real-combat notes

Source: Internet
Author: User

Shell Footstep Source code:

[Email protected]_ecs imooc_shell]$ lscheck_http_log.sh check_nginxserver.sh master_control.sh system_info.sh

Master_control.sh: The main control footsteps, other footsteps this script calls

############################################### file name: master_control.sh# author:  liuxiao# mail: [email protected]# created time: 2016-08-16 14:55##### ##########################################!/bin/bashdeclare -a ssharrayi=1numbers= "0" For script _file in  ' ls -i  "master_control.sh"  ./' do    echo -e  "\ e[1;34mthe script: ${i} ==> \e[0m "\e[1;35m${script_file}\e[0m"      grep -e  "^\ #Program  function"  ${script_file}    ssharray[$i]=${script_ file}    numbers= "${numbers} | ${i}"     i=$ ((i+1)) Donewhile  truedo    read -p  "please input a number,the  ' 0 '   is exit, [ ${numbers} ]:  " execshell    if [[ !  ${execshell} =~ ^[0-9]+ ]];then        exit 0     fi    if [  $execshell  -eq 0 ];then         exit 0    else         /bin/bash ./${ssharray[$execshell]}    fidone

System_info.sh: Display some information about the system

############################################### file name: system_info.sh# author:  liuxiao# mail: [email protected]# created time: 2016-08-16 19:30########### ####################################!/bin/bash#program function:display some system  information.clearos_bit=$ (uname -m)     echo -e  "\e[1;34mos_bit ==>  \e[1;32m$os_bit\e[0m "os_release=$ (lsb_release -a | grep description | cut  -F 2)     echo -e  "\e[1;34mos_release ==> \e[1;32m$os_ release\e[0m "kernel_release=$ (uname -r)     echo -e " \e[1;34mkernel_release  ==> \e[1;32m$kernel_release\e[0m "echo#network card infonet_card_name=$ (ip addr  | grep inet | awk  ' {print  $NF} ') net_card_ip=$ (ip addr |  Grep inet | awk  ' {print $2} '  | cut -f 1 -d  '/') i=0;j=0for name in  $Net _card_name    #将所有网卡的名称放入name_array数组中do     name_array[i]= $name      i=$ ((i+1)) donefor ip in  $Net _card_ip    #将所有网卡的IP放入ip_array数组中do     ip_array[j]= $ip     j=$ ((j+1)) donei=0;j=0for time in   $Net _card_name    #打印网卡名称和对应的IP, time is the variable that controls the number of cycles do    echo -e  "\e[1;34m${name_array[i]} ==> \e[1;32m${ip_array[j]}\e[0m"      i=$ (i+1) ); j=$ ((j+1)) doneecho#network statusping -c 2 www.baidu.com &>/dev/null  && echo -e  "\e[1;34mnetwork connection is ok\e[0m"  | |  echo -e  "\e[1;34mnetwork connection is false\e[0m" Echo#logged usersecho  -e  "\e[1;34mlogged users\e[0m "echo -e " \e[1;34m ' Who ' \e[0m "echo#mem_usagessystem_mem_usage=$ (awk  '/MemTotal/{total=$2}/ memfree/{free=$2}end{print  (total-free)/1024} '  /proc/meminfo)    #系统已经使用的内存apps_mem_usage =$ ( awk  '/memtotal/{total=$2}/memfree/{free=$2}/^cache/{cached=$2}/buffers/{buffers=$2}end{print  ( total-free-cached-buffers)/1024} '  /proc/meminfo)    #应用程序使用的内存echo  -e  "\e[1;34msystem_ mem_usage ==> \e[1;32m${system_mem_usage}m\e[0m "echo -e " \e[1;34mApps_mem_usage == > \e[1;32m${apps_mem_usage}m\e[0m "echo#load averageload_average=$ (top -n 1 -b  | grep  "Load average:"  | awk  ' {print $12 $13 $14} ') echo  -e  "\e[1;34mload_average ==> \e[1;32m${load_average}\e[0m" Echo#disk infodisk_info =$ (df -hp | grep -ve  "Filesystem|tmpfs"  | awk  ' {print $1  "    " $5} ') echo -e  "\e[1;34mdisk_info:\n\e[1;32m${disk_info}\e[0m" 

check_nginxserver.sh: Check nginx status

############################################### file name: check_nginxserver.sh# author:  liuxiao# mail: [email protected]# created time: 2016-08-20 10:44##### ######################################### #Program  function:check nginxserver status code.# !/bin/bashnginxserver= ' http://www.baidu.com ' check_nginx_server () {    echo -e  "\e [1;34mnginxserver = \e[1;32m${nginxserver}\e[0m "    status_code= ' curl -m  5 -s -w %{http_code} ${nginxserver} -o /dev/null '      echo -e  "\e[1;34mstatus_code = \e[1;32m${status_code}\e[0m"     if  [  $Status _code -ne 200 ];then        echo  -e  "\e[1;34mthe http status code is abnormal,please check your  nginxserver\e[0m "    elif [  $Status _code -eq 200 ];then         echo -e  "\e[1;34mthe nginxserver is ok\e[0m"      fi}check_nginx_server

check_http_log.sh: Check the HTTP access log

############################################### file name: chech_http_log.sh# author:  liuxiao# mail: [email protected]# created time: 2016-08-19 21:59##### ######################################### #Program  function:nginx ' s log analysis#!/bin/ Bashlogfile_path= '/home/wwwroot/index/log/access.log ' Check_http_status () {    http_status_ Codes= (' cat  $Logfile _path | grep -ioe  ' http\/1\.[ 1|0]\ "[[: Blank:]][0-9]{3}"  | awk -f ' [ ]+ '   ' {         if ($2>=100&&$2<200)              {i++}        else if ($2>=200&&$2<300)             {j++}         else if ($2>=300&&$2<400) &NBSP;&NBSP;&NBsp;         {k++}         Else if ($2>=400&&$2<500)              {n++}        else if ($2>=500)              {p++}        }end{             print i?i:0,j?j:0,k?k:0,n?n:0,p?p : 0,i+j+k+n+p            } '           ')     echo -e  "\e[1;34mthe number of http  status[100+]: \e[1;32m${http_status_codes[0]}\e[0m "    echo -e " \e[1; 34mthe number of http status[200+]: \e[1;32m${http_status_codes[1]}\e[0m "     echo -e  "\e[1;34mthe number of http status[300+]: \e[1;32m${http_status_codes[2]} \e[0m "    echo -e " \e[1;34mthe number of http status[400+]:  \e[1;32m${http_status_codes[3]}\e[0m "    echo -e " \e[1;34mthe number  of http status[500+]: \e[1;32m${http_status_codes[4]}\e[0m "    echo  -e  "\e[1;34mall request numbers: \e[1;32m${http_status_codes[5]}\e[0m"}Check_http_ Code () {    http_code= (' cat  $Logfile _path | grep -ioe  "HTTP\/1\.[ 1|0]\ "[[: Blank:]][0-9]{3}"  | awk -v total=0 -F  ' [ ]+ '   ' {         if ($2!= "")              {code[$2]++;total++}        else             {exit}        }end{             print code[404]?code[404]:0,code[403]?code[403]:0,total         } ')     echo -e  \e[1;34mthe  number of http status[404]: \e[1;32m${http_code[0]}\e[0m "     echo -e  "\e[1;34mthe number of http status[403]: \e[1;32m${http_code[1]}\e[ 0m "    echo -e " \e[1;34mall request numbers: \e[1;32m${http_code[ 2]}\e[0m "}check_http_statuscheck_http_code


This article is from the "we_need_to_try" blog, make sure to keep this source http://liuxiao255.blog.51cto.com/10551403/1840541

Mu class Network Shell real-combat notes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.