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