# listPoolSnap.pl
#
# by Vijayababu Dandi
# Version 1.0
# Aug 27, 2009
##############################################################################################
# Perl must be installed and running on the Linux server where this utility will be used.
# NSS must be installed to get the VFS support.
# (The SDK for this API set can be downloaded from http://developer.novell.com/wiki/index.php/# Virtual_File_Services_for_NetWare.)
##############################################################################################
#
# This is used to get the directory quotas on a nss directory.
#
##############################################################################################
sub SetDataStream($*)
{
my $fh = $_[0];
my $datastream = $_[1];
my $command;
my $result;
my $error;
$command = "";
seek $fh, 0, 0;
if (!syswrite($fh, $command, length($command)))
{
$result .= "Unable to send datastream command to NDS management. ";
seek $fh, 0, 0;
if (sysread($fh,$error, 1000))
{
$result .= $error;
}
$result .= "\n";
}
return $result;
}
sub WriteCommand($*)
{
my $fh = $_[0];
my $result;
my $reply;
my $error;
my $command = $_[1];
seek $fh, 0, 0;
if (!syswrite($fh, $command, length($command)))
{
$result .= "Unable to send command to virtual file. ";
seek $fh, 0, 0;
if (sysread($fh, $error, 1000))
{
$result .= $error;
}
$result .= "\n";
}
else
{
seek $fh, 0, 0;
my $readLen = 999;
while ($readLen)
{
$readLen = sysread($fh, $reply, 1000);
$result .= $reply;
}
}
return $result;
}
sub dirQuota($)
{
my $dirName = $_[0];
my $result;
my $ret;
my $nssResult;
$command = "";
if (!($ret = SetDataStream(FILE, "command")))
{
$result .= $ret;
$nssResult = WriteCommand(FILE,"$command");
}
ParseDirQuota($nssResult);
}
sub ParseDirQuota($)
{
my $xml = $_[0];
my $result;
my @xml;
my $ret;
my $size;
my $errno;
my $usedSize;
my $description;
my $reporter;
@xml = $xml =~ /(.*?)<\/getFileInfo>/gs;
$ret ='';
foreach $result (@xml)
{
if ($result =~ //s)
{
$errno = $1;
}
if ($result =~ /(.*?)<\/description>/gs)
{
$description = $1;
}
if ($result =~ /(.*?)<\/reporter>/gs)
{
$reporter = $1;
}
if ($errno != 0)
{
print "\n-----------------------------------------------------------\n".
"Error No : $errno\n".
"Description : $description\n".
"Reporter : $reporter\n".
"-----------------------------------------------------------\n";
return;
}
$poolName = "";
$poolState = "";
if ($result =~ /(.*?)<\/quotaAmount>/s)
{
$size = $1;
}
if ($result =~ /(.*?)<\/usedAmount>/s)
{
$usedSize = $1;
}
if ($size == 9223372036854775807)
{
print "\n------------------------------------------------------------\n".
" quota not assigned\n".
"------------------------------------------------------------\n";
return;
}
else
{
$size = $size/1024;
$usedSize = $usedSize/1024;
print "\n---------------------------------------------------------\n".
"quota Amount(in KB) : $size \n".
"used Amount(in KB) : $usedSize \n".
"----------------------------------------------------------\n";
return 0;
}
}
}
open(FILE,"+>", "/_admin/Manage_NSS/files.cmd")
or die "Error opening NSS management file ($!) on server";
MAIN :while (1)
{
my $action;
do
{
print "1.To get directory quota\n".
"2.Exit\n".
"Select Action: ";
chomp($action = );
}while ($action != 0 && ($action < 1 || $action > 2));
if ($action == 1)
{
my $dirName;
print "Enter directory Name(with fully qualified path) to find directory quota: ";
chomp($dirName = );
dirQuota($dirName);
}
else
{
exit(0);
}
}
close(FILE);