LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-19-2005, 05:33 PM   #1
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Rep: Reputation: 30
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
 
Old 01-19-2005, 11:52 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl-how to print to file satimis Programming 4 11-17-2004 10:56 PM
Samba and Print Quotas randombob Linux - Networking 0 10-21-2004 06:19 AM
linux print server with quotas! jhp Linux - Networking 0 09-01-2004 07:49 AM
perl print double in proper format rajatgarg Programming 1 01-30-2004 12:57 PM
Perl print Multiline help! CragStar Programming 1 02-06-2002 08:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration