bash腳本示例3

1、寫一個腳本實現列出以下菜單給用戶:

(1)show disk info

(2)show memory info

(3)show cpu info

(*)quit


    #/bin/bash

    #

    cat << EOF

    (1)show disk info

    (2)show memory info

    (3)show cpu info

    (*)quit

    EOF


    read -p "Enter the corresponding number to display the corresponding information, or enter any character to exit: " number


    if [ $number == 1 ]; then

        fdisk -l

    elif [ $number == 2 ]; then

        free -h

    elif [ $number == 3 ]; then

        lscpu

    fi


2、用bash實現統計訪問日誌文件中狀態碼大於等於400的IP數量並排序


    這裏以yum倉庫訪問日誌文件yum.access.log爲例。

    [root@192 ~]# cat yum.access.log 

    192.168.1.220 - - [16/May/2016:20:26:59 +0800] "GET /centos/7/os/x86_64/Packages/MySQL-python-1.2.3-11.el7.x86_64.rpm HTTP/1.1" 200 83560 "-" "urlgrabber/3.10 yum/3.4.3" "-"

    192.168.1.221 - - [16/May/2016:20:36:59 +0800] "GET /?release=7&arch=x86_64&repo=os&infra=stock HTTP/1.1" 200 2391 "-" "urlgrabber/3.10 yum/3.4.3" "-"

    192.168.1.222 - - [16/May/2016:20:38:25 +0800] "GET /centos/7/os/x86_64%3Cbr%3Ehttp%3A//mirror.centos.org/centos/7/os/x86_64%3Cbr%3E/repodata/repomd.xml HTTP/1.1" 404 168 "-" "urlgrabber/3.10 yum/3.4.3" "-"

    ...

    [root@192 ~]# grep 'HTTP/1.1" [456]' yum.access.log | cut -d ' ' -f 1 | sort | uniq -c

      1 192.168.1.222

      2 192.168.1.223

      1 192.168.1.224

      1 192.168.1.225

      1 192.168.1.226

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章