gpt4 book ai didi

linux - 列出Linux中配额超过指定值的用户

转载 作者:太空宇宙 更新时间:2023-11-04 03:34:37 25 4
gpt4 key购买 nike

我花了很多时间尝试创建配额检查脚本,但没有得到我需要的结果。

我正在使用 for 循环来迭代 awk 命令来搜索大于 3000000 的值。

输出配额的命令基础:

for i in `awk '{print $2}' /etc/userdomains |  grep -v "nobody" | sort -u`
do
quota -v -u $i
done

每次迭代的输出:

Disk quotas for user exampleuser (uid 2599): 
Filesystem blocks quota limit grace files quota limit grace
/dev/sda1 8 0 0 10 0 0
/dev/sdb1 0 0 0 0 0 0
/dev/sdc1 57792 0 0 2511 0 0
/dev/sdd1 0 0 0 0 0 0
/dev/sde1 0 0 0 0 0 0

我打算通过管道传输 awk 命令来打印第 1 行;字段 5 AND 行等于或大于 3;字段 2(如果字段 2 大于 50000)

所以想要的输出是:

exampleuser
57792

exampleuser 57792

到目前为止,我无法在 awk 中使用不同的方法获得这些结果。

这是我最近的两次尝试(基于大于 3000000 的值):

for i in `awk '{print $2}' /etc/userdomains |  grep -v "nobody" | sort -u`
do
quota -v -u $i | awk '{ if ($2 >= 3000000) print $0 ; else;}'
done

输出:

Disk quotas for user bforrest (uid 2108): 
Filesystem blocks quota limit grace files quota limit grace
Disk quotas for user bible (uid 500):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdc1 12230716 0 0 10168 0 0
Disk quotas for user bigbeau (uid 1608):
Filesystem blocks quota limit grace files quota limit grace
Disk quotas for user bilgem (uid 3299):
Filesystem blocks quota limit grace files quota limit grace
Disk quotas for user billbell (uid 2872):
Filesystem blocks quota limit grace files quota limit grace
Disk quotas for user biosalus (uid 3215):
Filesystem blocks quota limit grace files quota limit grace
Disk quotas for user bkeating (uid 1104):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdc1 3106480 0 0 9636 0 0
Disk quotas for user blaaraba (uid 2931):
Filesystem blocks quota limit grace files quota limit grace
Disk quotas for user blackbird (uid 1666):
Filesystem blocks quota limit grace files quota limit grace

另一个:

for i in `awk '{print $2}' /etc/userdomains |  grep -v "nobody" | sort -u`
do
quota -v -u $i \
| awk '{ if (NR >= 3 && $2 >= 3000000) print $0 ; else;}' \
| cut -d "*" -f1
done

输出:

  /dev/sdc1 55948456       0       0           45806       0       0        
/dev/sdd1 91428904 0 0 97739 0 0
/dev/sdd1 512000
/dev/sdc1 60275820 0 0 10594 0 0
/dev/sdb1 512460
/dev/sdb1 93819732 0 0 47951 0 0
/dev/sdd1 527613532 0 0 11935 0 0
/dev/sdd1 56922524 0 0 60761 0 0
/dev/sdc1 307664
/dev/sdb1 65851960 0 0 257999 0 0

也许我的方法完全不对劲。对此有什么想法吗?

更新:

找到了一个更好的命令(repquota -a)来报告配额。更加一致,因为它不会根据文件所在的位置而变化:

for i in `awk '{print $2}' /etc/userdomains |  grep -v "nobody" | sort -u`
do
repquota -a | awk {'print $1 " " $3'} | grep -w $i \
| awk '{if ($2 >= 5000000) print $0 ; else;}'
done

输出:

a4fundjs 55948456
actifeve 12535196
aepromo 13224160

最佳答案

为您提供原始输入

awk 'NR==1{print $5} NR>2 && $2>50000 {print $2}'

将打印

exampleuser                                                                                                                                                                                                 
57792

关于linux - 列出Linux中配额超过指定值的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32038522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com