Prerequisites: Unixy OS with quotas enabled, Perl 5.8.8, Quota.pm 1.6.3.
I always like to provide some sort of progress display for my programs. As a sysadmin, there are times when it might be prudent to check users' files without inspecting them by hand, e.g. when checking for parasitical exploits in websites. The number of files and/or amount of disk space used seem like reasonable measurements for keeping track of that progress.
So you use Quota; and get coding, right?
Except that you may not know beforehand whether you're scanning a local file system, or a remote file system, and Quota.pm requires that you have a magical device identifier before asking what the quota is.
The manual says that you should do something like this:
my $r_uid; # User's real UID
my $dev = Quota::getqcarg($directory);
my @quotadata = Quota::query($dev, $r_uid);
Now we've got some nice quota data, in the following order:
Current blocks used, block soft limit, block hard limit, soft block time limit, current inodes used, inode soft limit, inode hard limit, soft inode time limit.
But no, there's a catch! If you run this on the local file server, rather than via NFS/RPC, then Quota::query() will barf, because $dev is erroneous. How did that happen?
Well, Quota::query() doesn't work if the device is local!
So we have to do this after calling Quota::getqcarg():
if ($dev =~ m{^/dev/}) {
$dev = "127.0.0.1:$directory";
}
The irony is then that there appears to be a need for an RPC listener on the loopback device, at least.
Anyway, I hope this is useful; it helped me to make tings Just Work.
No comments:
Post a Comment