2

I am trying to write a bash script that will tell me the default "Block grace time" for a given partition in a predictable unit. The closest I have found so far is to use repquota and parse the output, but it is inconsistent. Sometimes it reports days as you see below "7days", as you can see blow on the 3rd line.

[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
[...]

For shorter periods, it reports as "4:10" which means 4 hours 10 minutes. For values < 30 seconds, it reports 00:00, and between 30 seconds and 1 minute, it reports 00:01.

How can I get the actual setting Block grace time value, without having it be made more "human readable" so it can be parsed by a program reliably?

Thanks!

1

We have a similar issue with GPFS quota reports. The most basic solution would be to have a regex that lets you get whatever is there in any of the form you'd expect to encounter and then analyse that in a next step. For example in 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)

Given the example lines

Block grace time: 7days; Inode grace time: 7days
Block grace time: 4:10; Inode grace time: 7days

You'd get the following output:

Found days: 7 or in seconds: 604800
Found hours: 4 and minutes: 10 or in seconds: 15000

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.