我需要在集群中找到磁盘空间> =85%的主机。我能走这么远
host df -h / | awk ‘{print $1,$5 }’
# Output
<host1>
Filesystem Use%
/dev/mapper/vg-root 88%
<host2>
Filesystem Use%
/dev/mapper/vg-root 68%
<host3>
Filesystem Use%
/dev/mapper/vg-root 95%当我这么做
df -h / | awk ‘{print $1,$5 }’ | awk ‘$2 >=85 {print}’然后,它从输出中省略主机名。
我希望看到具有磁盘利用率>=85%的主机。像这样
host1
85%
host3
95%在下一个输出中,我只想看到主机名
host1
host3然后,我想运行我们的自定义游戏手册来清理那些主机上的磁盘空间。
例如:
diskclean.yaml host1
diskclean.yaml host3谢谢
主机df -h /的输出
host1 :
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg-root 20G 18G 2G 90% /
host2 :
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg-root 14G 11G 3.4G 77% /
host3 :
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg-root 12G 11G 1G 91.6% /
host4 :
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg-root 15G 15G 0 100% /
host5 :
Host didn’t respond. [No response]host5输出是噪声。
发布于 2020-05-18 03:14:31
试一试
host df -h / | awk ‘{print $1,$5 }’ | grep -oE '<(.*)>|[0-9]+%'| sed 'N;s/\n/ /;s#[<>%]##g'| awk ' {if($2>=85) print $1"\n"$2"%\n"}'演示:
$cat file.txt
<host1>
Filesystem Use%
/dev/mapper/vg-root 88%
<host2>
Filesystem Use%
/dev/mapper/vg-root 68%
<host3>
Filesystem Use%
/dev/mapper/vg-root 95%
$grep -oE '<(.*)>|[0-9]+%' file.txt | sed 'N;s/\n/ /;s#[<>%]##g'| awk ' {if($2>=85) print $1"\n"$2"%\n"}'
host1
88%
host3
95%
$只适用于打印主机名
host df -h / | awk ‘{print $1,$5 }’ | grep -oE '<(.*)>|[0-9]+%'| sed 'N;s/\n/ /;s#[<>%]##g'| awk ' {if($2>=85) print $1}'演示:
$grep -oE '<(.*)>|[0-9]+%' file.txt | sed 'N;s/\n/ /;s#[<>%]##g'| awk ' {if($2>=85) print $1}'
host1
host3
$https://stackoverflow.com/questions/61858614
复制相似问题