加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

shell脚本

发布时间:2020-12-16 01:41:56 所属栏目:安全 来源:网络整理
导读:1打印九九乘法口诀表 for i in `seq 9` ;do for j in `seq 9` ;do if [ $i -ge $j ];then let sum=${i}*${j} echo -e "${i}x${j}=$sumtc" fi done echodone 2.检查磁盘空间,一旦发现任何分区利用率高于80%,就发出警报 disk=`fdisk -l | egrep -o "^/dev/
1打印九九乘法口诀表

for i in `seq 9` ;do
    for j in `seq 9` ;do
        if [ $i -ge $j ];then
            let sum=${i}*${j}
            echo -e "${i}x${j}=$sumtc"
        fi                                                                                                              
    done
    echo
done

2.检查磁盘空间,一旦发现任何分区利用率高于80%,就发出警报

disk=`fdisk -l | egrep -o "^/dev/[[:alpha:]]+[0-9]"` 
#disk=`lsblk | sed -rn "s/^├─([[:alpha:]]{3}[1-9]).*/1/p"`
max_num=0
for name in `echo $disk`;do
        #有可能是交换空间,df命令就没有显示。直接跳过
        if ! df | egrep -o "^$name.*" &> /dev/null;then
                continue
        fi
        #获取使用空间和inodes
        num=`df | egrep -o "$name.*" | tr -s " " "%" | cut -d "%" -f 5`
        Inodes_num=`df -i | egrep -o "$name.*" | tr -s " " "%" | cut -d "%" -f 5`
        #使用空间和inodes大于80就发出警告。
        if [ $num -ge 80 -o $Inodes_num -ge 80 ];then
                if [ $num -gt $max_num ];then
                        max_num=$num
                        max_name=$name
                        max_Inodes_num=$Inodes_num
                elif [ $num -eq $max_num ];then
                        max_equal_num=$num
                        max_equal_name=$name
                        max_equal_Inodes_num=$Inodes_num
                fi
        fi
done
#判断是否有超过80的
if [ $max_num -ne 0 ];then
        let remaining=100-$max_num
        let Inodes_remaining=100-$max_Inodes_num
        #判断是否有两个分区使用量一样
        if [ -z $max_equal_num ];then
                wall The $max_name disk is about to run out,Only the remaining disk is 
                ${remaining}% and Inodes${Inodes_remaining}%
        else
                wall The $max_name and $max_equal_name disk is about to run out,Only 
                the remaining disk is ${remaining}% and Inodes${Inodes_remaining}%
        fi
fi

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读