LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   perl: get quotas and print on webpage (https://www.linuxquestions.org/questions/programming-9/perl-get-quotas-and-print-on-webpage-279884/)

hamish 01-19-2005 05:33 PM

perl: get quotas and print on webpage
 
Hello

I'm trying to sort out quotas for my users, however, I'm having real problems working with perl.

What my script should do is to get the user's quota and usage using repquota -a. Then grep and awk the lines in order to get the correct digit.

here is code at the moment:
Code:

#!/usr/bin/perl
print ("Content-type: text/html\n\n");

$user=christine;

# get quota
system("/usr/sbin/repquota -a > /tmp/quota");
system("grep -Eir $user /tmp/quota > /tmp/quota2");
system("awk '{print \$4}' /tmp/quota2 > /tmp/quota3");

# get usage
system("awk '{ print \$3 }' /tmp/quota2 > /tmp/quota4");
$quota=system("grep -Eir '[[:digit:]]' /tmp/quota4");


$usage=system("grep -Eir '[[:digit:]]' /tmp/quota3");

# change to mb
$quotamb=int($quota / 1024);
$usagemb=int($usage / 1024);

print ("<p>Your username is: $user</p>");
print ("<p>Your quota is: $quotamb MB</p>");
print ("<p>Your usage is: $usagemb MB</p>");

#rm /tmp/quota

The output is here: http://hamishnet.homelinux.com/cgi-bin/qtest.pl
As you can see, it doesn't work, and I'm having touble finidng out why.

1. it seems to print the the variables $quota and $usage at the very top. I don't really understand why.
2. the script doesn't seem to divide the $quota and $usage variables by 1024. It just puts the $quotamb and $usagemb to 0.

So my question is: (a) what am I doing wrong, and (b) how can I get it working like I want?

Thanks in advance for all your help.
hamish

chrism01 01-19-2005 11:52 PM

FYI, system() rtns the exit status of the called cmd, not the stdout (or stderr) of the called cmd.
I recommend you try this module: http://search.cpan.org/~tomzo/Quota-1.5.0/Quota.pm

HTH


All times are GMT -5. The time now is 07:13 AM.