我正在尝试编写一个bash脚本来告诉我一个可预测单元中给定分区的默认“阻塞宽限时间”。 到目前为止,我发现的最接近的是使用repquota和parsing输出,但它是不一致的。 有时会在“7天”之后看到几天,正如您在第三行看到的那样。
[root@hostname]# repquota -g -p / *** Report for group quotas on device /dev/mapper/vg_in1-lv_root Block grace time: 7days; Inode grace time: 7days Block limits File limits Group used soft hard grace used soft hard grace ---------------------------------------------------------------------- root -- 2135928 0 0 0 59727 0 0 0 bin -- 480 0 0 0 28 0 0 0 tty -- 24 0 0 0 2 0 0 0 [...]
如果时间较短,则报告为“4:10”,即4小时10分钟。 对于<30秒的值,报告00:00,30秒到1分钟报告00:01。
我怎样才能得到实际的设置阻塞宽限时间的价值,而不是让它更“人类可读”,所以它可以被程序可靠地parsing?
谢谢!
我们与GPFS配额报告有类似的问题。 最基本的解决scheme将是有一个正则expression式,让你得到任何forms的任何forms,你会遇到的,然后分析下一步。 例如在Python中
#!/usr/bin/env python import re import sys GRACE_REGEX = re.compile(r"Block grace time: (?P<days>\d+)\s*days?|(?P<hours>\d+):(?P<minutes>\d+)") for line in sys.stdin.readlines(): grace = GRACE_REGEX.search(line) if not grace: continue grace_groups = grace.groupdict() if grace_groups.get('days', None): print "Found days: %d or in seconds: %d" % ( int(grace_groups['days']), int(grace_groups['days']) * 86400) if grace_groups.get('hours', None): print "Found hours: %d and minutes: %d or in seconds: %d" % ( int(grace_groups['hours']), int(grace_groups['minutes']), int(grace_groups['hours']) * 3600 + int(grace_groups['minutes']) * 60)
给出示例行
Block grace time: 7days; Inode grace time: 7days Block grace time: 4:10; Inode grace time: 7days
你会得到以下输出:
Found days: 7 or in seconds: 604800 Found hours: 4 and minutes: 10 or in seconds: 15000