linux shell中的%3e,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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值