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!

Paul
  • 21
  • 1

2 Answers2

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
Itkovian
  • 11
  • 2
0

You could use quotatool to get the existing block and inode grace times in seconds, for example:

quotatool -v -n -u -b -t "1 day" /home
quotatool: using uid (null)
quotatool: working with block limits
quotatool: using filesystem /home
quotatool: filesystem /home has device node /dev/xvda4
quotatool: 
quotatool: Limit          Old              New             
quotatool: -----          ---              ---             
quotatool: block grace:   23500            86400           

quotatool -v -n -u -i -t "1 day" /home
quotatool: using uid (null)
quotatool: working with inode limits
quotatool: using filesystem /home
quotatool: filesystem /home has device node /dev/xvda4
quotatool: 
quotatool: Limit          Old              New             
quotatool: -----          ---              ---             
quotatool: inode grace:   9400000          86400           

Then you could take the Old column value from last line. Note that the output above goes to standard error, not standard out and the Old and New columns are tab, not space separated.

So, using Bash you could do the following:

quotatool -v -n -u -b -t "1 day" /home 2>&1 | tail -n1 | awk '{ print $4 }'
23500

quotatool -v -n -u -i -t "1 day" /home 2>&1 | tail -n1 | awk '{ print $4 }'
9400000