bash脚本,用于计算给定分区的已用磁盘空间百分比 [英] bash script that computes used diskspace percentage for given partition

查看:75
本文介绍了bash脚本,用于计算给定分区的已用磁盘空间百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bash脚本,用于计算给定分区的已用磁盘空间百分比:

I have a bash script that computes used diskspace percentage for given partition:



    df -k $devname | grep -v ^File | awk '{printf ("%i",$3*100 / $2); }

在长名称分区上不起作用,因为名称将其他列推到下一行,我该如何解决?

it doesn't work on a partition with long name because the name pushes the other columns to the next line, how do I fix this?


df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup60-ROOT
                     2865493440 2222006740 497927968  82% /
tmpfs                 30913808         0  30913808   0% /dev/shm
/dev/sda1               495844    103347    366897  22% /boot

推荐答案

df -P (可移植性)选项使用与posix兼容的输出格式,并保留所有内容在一排.您还可以使用 sel 简化 awk 部分.

The -P (portability) option for df use a output format compliant with posix and keeps everything in one line. You can also simplify the awk part using sel.

这篇关于bash脚本,用于计算给定分区的已用磁盘空间百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆