#!/usr/bin/perl -w # Shows cpanel users whose quota is over 80% # Rename to checkquota, chown root and chmod 0700 # Usage: checkquota [username] ############################################################################### # Author: Juan R. Pozo - http://html.conclase.net/cp/scripts/ # Released on September 18, 2003 ############################################################################### # This software is released into the public domain. Use at your own risk. # The author holds no rights or responsibilities related to this software. ############################################################################### use strict; my @users; if (defined($ARGV[0]) && $ARGV[0] =~ /^\w{1,8}$/) { if (-r "/var/cpanel/users/$ARGV[0]") { @users = ($ARGV[0]); } else { die("User data file not found\n"); } } else { opendir(CPU, "/var/cpanel/users") or die("Can't open cpanel users directory: $!"); @users = grep { !/^\./ } readdir(CPU); closedir(CPU); } my ($quota, $quotamax); foreach my $user (@users) { $quota = 0; $quotamax = 0; my @quota = `quota -u $user`; # Sample output: # /dev/sda2 452 30720 30720 94 0 0 foreach my $line (@quota) { if ($line =~ /^\s*\S+\s+(\d+)\D+(\d+)/) { $quota += $1; $quotamax = $2; } } if (not $quotamax) { print "User $user has no quota set\n"; } elsif ($quota/$quotamax > 0.80) { printf( "%8s: %.2fMB de %.2fMB (%.2f%%)\n", $user, $quota/1024, $quotamax/1024, ($quota/$quotamax)*100 ); } } exit;