写个shell检测多台机器磁盘

编写脚本检测多台机器磁盘使用情况

  1. 将需要检测的机器的ip统一touch到一个文件里面,此处我们命名为 linux_Server_List.config

  2. 然后写shell就OK了

    shell如下
    在这里插入图片描述
    在这里插入图片描述
    #!/bin/bash
    #文件名:DiskCheck.sh
    #用途:批量检查磁盘空间
    cd /DiskCheck/
    #删除之前已经存在的文件
    rm -rf df_all_grep.txt
    #对原先的结果进行备份
    mv df_result.txt df_result_bak.txt
    rm -rf df_result1.txt
    #for循环对文件内的ip进行遍历
    for h in cat linux_Server_List.config
    do
    #连接机器执行df -h 后写进 df_temp.txt
    echo "$h : ssh -o ConnectTimeout=3 -o ConnectionAttempts=5 -o PasswordAuthentication=no -o StrictHostKeyChecking=no $h "hostname && df -h"" >df_temp.txt
    echo " head -n 1 df_temp.txt : cat df_temp.txt | grep -w '/$'" >> df_all_grep.txt
    echo " head -n 1 df_temp.txt : cat df_temp.txt | grep '/data'" >> df_all_grep.txt
    echo " head -n 1 df_temp.txt : cat df_temp.txt | grep '/yhdx'" >> df_all_grep.txt
    echo " head -n 1 df_temp.txt : cat df_temp.txt | grep '/log'" >> df_all_grep.txt
    echo " head -n 1 df_temp.txt : cat df_temp.txt | grep '/opt'" >> df_all_grep.txt

done

rm -rf df_temp.txt

cat df_all_grep.txt | awk ‘{print $1"|"$3"|"$9"|"$10}’ >>df_result1.txt

sed -i ‘s/123.57.140.241/10.172.197.195/g’ df_result1.txt

cat df_result1.txt | sort -t’|’ -k 3 -r -n | head -n 50 >>df_result.txt

cat df_result1.txt | sort -t’|’ -k 3 -r -n | head -n 300 >1.txt

cat 1.txt | grep nicetuan-api-base >2.txt

head df_result.txt

3、可以写进crontab 定时执行

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值