на п0нTаL0o0n-хостинге у бородачей работает скрипт:#!/usr/bin/perl
use lib qw(/site/perl/lib /site/perl/sys);
use strict; use AGAVA::Hosting::Config; use AGAVA::DBI; use AGAVA::Hosting::HostingData;
use Data::Dumper; use AGAVA::Hosting::Utils;
BEGIN {
open(STDERR, ">>/home/r/register.h17.ru/log/disk_usage_mysql_quota.pl.log");
}
#exit 1;
#lock();
my $cfg = new AGAVA::Hosting::Config;
my $dbh = AGAVA::DBI->connect(AGAVA::Hosting::Config->new());
my $dbh1 = AGAVA::DBI->connect(AGAVA::Config->new($cfg, $cfg->get('MYSQL_DB_CONF'))) or return undef;
my $sth;
my $adomain = $cfg->get('DEFAULT_ADOMAIN');
my $adomain1 = $adomain;
$adomain =~ s/\./\\./;
my $hd = AGAVA::Hosting::HostingData->new();
my $take_update = 0;
trace("Start disk_usage_mysql_quota [ ***** ]");
my $count;
my $count1;
my $count2;
my $count0;
my $count3;
my %disc_quota = undef;
my %mega_hash_nah1 = undef;
open (FH, "< /etc/passwd") or die ("err1 !!!");
while (<FH>)
{
if($_ =~ /^(.*):\*:(\d+):\d+:.*\.$adomain:\/home\/.{1}\/.*\.$adomain:.*$/)
{
$mega_hash_nah1{$2} = $1;
}
}
close FH;
my $repquota_cmd = $cfg->get('REPQUOTA_CMD');
my $first_uid = $cfg->get('START_UID');
my $last_uid = $cfg->get('LAST_UID');
open(my $repquota_fh, "$repquota_cmd |");
while (my $line = <$repquota_fh>)
{
my ($uid,undef,$sz,undef,$max_sz,undef,$nm,undef,$max_nm) = split(/\s+/,$line);
if (($first_uid <= $uid) and ($last_uid >= $uid))
{
my $name;
if ($name = $mega_hash_nah1{$uid})
{
$disc_quota{$name} = {used => $sz, allow => $max_sz};
}
}
}
close $repquota_fh;
$sth = $dbh->prepare("select name,domain,db,inodes,du_limit from hpersons where status <> 'a'");
$sth->execute();
while (my $data = $sth->fetchrow_hashref)
{
$count0++;
if (defined($data->{name}) and defined($data->{domain}))
{
if ($data->{db})
{
my $done_changes = 0;
my $quota = $disc_quota{$data->{name}};
my $used = 0;
my $quota_cmd = sprintf($cfg->get('DB_SIZE_CMD'),$data->{name});
open(my $rc_quota_cmd, "$quota_cmd |");
my $rc = <$rc_quota_cmd>;
close $rc_quota_cmd;
my ($used,@tmp) = split(/\s+/,$rc);
if ($used eq "NO_DB")
{
my $sth2 = $dbh->prepare('update hpersons set db = ? where name = ?');
$sth2->execute(0,$data->{name});
$count2++;
}
unless ($used =~ /\d+/) { $used = 0;}
$used = $used + $quota->{used};
#warn " -- $used -- \n";
my $sth2 = $dbh->prepare('update hpersons set quota = ? where name = ?');
$sth2->execute($used,$data->{name});
$count1++;
if($used <= $quota->{allow})
{
$done_changes = 1;
if($take_update)
{
$dbh1->do("UPDATE db SET Insert_priv='Y', Create_priv='Y', Update_priv='Y' WHERE Db='$data->{name}'");
}
else
{
$dbh1->do("UPDATE db SET Insert_priv='Y', Create_priv='Y' WHERE Db='$data->{name}'");
}
$hd->i_add_quota($data->{name},$data->{du_limit},$data->{inodes});
}
elsif($used >= $quota->{allow})
{
$done_changes = 1;
if($take_update)
{
$dbh1->do("UPDATE db SET Insert_priv='N', Create_priv='N', Update_priv='N' WHERE Db='$data->{name}'");
}
else
{
$dbh1->do("UPDATE db SET Insert_priv='N', Create_priv='N' WHERE Db='$data->{name}'");
}
#trace("block [ ".$data->{name}." ] : used [ $used ] : allow [".$quota->{allow}."]");
$hd->i_add_quota($data->{name},'1024',$data->{inodes});
$count3++;
}
if($done_changes)
{
$dbh1->do("FLUSH PRIVILEGES");
}
}
else
{
my $tmp = $disc_quota{$data->{name}};
my $sth2 = $dbh->prepare('update hpersons set quota = ? where name = ?');
$sth2->execute($tmp->{used},$data->{name});
$count++;
}
}
}
trace("End disk_usage_mysql_quota [ ***** ]");
$dbh->disconnect;
$dbh1->disconnect;
#unlock();
sub trace
{
my $msg = shift;
warn "[ ".localtime()." ] $msg \n";
}
#print $count0."\n";
#print $count."\n";
#print $count1."\n";
#print $count2."\n";
#print $count3."\n";
[ithelp8@entropy17 ~]$
[ithelp8@entropy17 ~]$
[ithelp8@entropy17 ~]$
[ithelp8@entropy17 ~]$ clear
[ithelp8@entropy17 ~]$ cat /site/Hosting/scripts/disk_usage_mysql_quota.pl
[ithelp8@entropy17 ~]$ clear
[ithelp8@entropy17 ~]$ cat /site/Hosting/scripts/disk_usage_mysql_quota.pl
#!/usr/bin/perl
use lib qw(/site/perl/lib /site/perl/sys);
use strict; use AGAVA::Hosting::Config; use AGAVA::DBI; use AGAVA::Hosting::HostingData;
use Data::Dumper; use AGAVA::Hosting::Utils;
BEGIN {
open(STDERR, ">>/home/r/register.h17.ru/log/disk_usage_mysql_quota.pl.log");
}
#exit 1;
#lock();
my $cfg = new AGAVA::Hosting::Config;
my $dbh = AGAVA::DBI->connect(AGAVA::Hosting::Config->new());
my $dbh1 = AGAVA::DBI->connect(AGAVA::Config->new($cfg, $cfg->get('MYSQL_DB_CONF'))) or return undef;
my $sth;
my $adomain = $cfg->get('DEFAULT_ADOMAIN');
my $adomain1 = $adomain;
$adomain =~ s/\./\\./;
my $hd = AGAVA::Hosting::HostingData->new();
my $take_update = 0;
trace("Start disk_usage_mysql_quota [ ***** ]");
my $count;
my $count1;
my $count2;
my $count0;
my $count3;
my %disc_quota = undef;
my %mega_hash_nah1 = undef;
open (FH, "< /etc/passwd") or die ("err1 !!!");
while (<FH>)
{
if($_ =~ /^(.*):\*:(\d+):\d+:.*\.$adomain:\/home\/.{1}\/.*\.$adomain:.*$/)
{
$mega_hash_nah1{$2} = $1;
}
}
close FH;
my $repquota_cmd = $cfg->get('REPQUOTA_CMD');
my $first_uid = $cfg->get('START_UID');
my $last_uid = $cfg->get('LAST_UID');
open(my $repquota_fh, "$repquota_cmd |");
while (my $line = <$repquota_fh>)
{
my ($uid,undef,$sz,undef,$max_sz,undef,$nm,undef,$max_nm) = split(/\s+/,$line);
if (($first_uid <= $uid) and ($last_uid >= $uid))
{
my $name;
if ($name = $mega_hash_nah1{$uid})
{
$disc_quota{$name} = {used => $sz, allow => $max_sz};
}
}
}
close $repquota_fh;
$sth = $dbh->prepare("select name,domain,db,inodes,du_limit from hpersons where status <> 'a'");
$sth->execute();
while (my $data = $sth->fetchrow_hashref)
{
$count0++;
if (defined($data->{name}) and defined($data->{domain}))
{
if ($data->{db})
{
my $done_changes = 0;
my $quota = $disc_quota{$data->{name}};
my $used = 0;
my $quota_cmd = sprintf($cfg->get('DB_SIZE_CMD'),$data->{name});
open(my $rc_quota_cmd, "$quota_cmd |");
my $rc = <$rc_quota_cmd>;
close $rc_quota_cmd;
my ($used,@tmp) = split(/\s+/,$rc);
if ($used eq "NO_DB")
{
my $sth2 = $dbh->prepare('update hpersons set db = ? where name = ?');
$sth2->execute(0,$data->{name});
$count2++;
}
unless ($used =~ /\d+/) { $used = 0;}
$used = $used + $quota->{used};
#warn " -- $used -- \n";
my $sth2 = $dbh->prepare('update hpersons set quota = ? where name = ?');
$sth2->execute($used,$data->{name});
$count1++;
if($used <= $quota->{allow})
{
$done_changes = 1;
if($take_update)
{
$dbh1->do("UPDATE db SET Insert_priv='Y', Create_priv='Y', Update_priv='Y' WHERE Db='$data->{name}'");
}
else
{
$dbh1->do("UPDATE db SET Insert_priv='Y', Create_priv='Y' WHERE Db='$data->{name}'");
}
$hd->i_add_quota($data->{name},$data->{du_limit},$data->{inodes});
}
elsif($used >= $quota->{allow})
{
$done_changes = 1;
if($take_update)
{
$dbh1->do("UPDATE db SET Insert_priv='N', Create_priv='N', Update_priv='N' WHERE Db='$data->{name}'");
}
else
{
$dbh1->do("UPDATE db SET Insert_priv='N', Create_priv='N' WHERE Db='$data->{name}'");
}
#trace("block [ ".$data->{name}." ] : used [ $used ] : allow [".$quota->{allow}."]");
$hd->i_add_quota($data->{name},'1024',$data->{inodes});
$count3++;
}
if($done_changes)
{
$dbh1->do("FLUSH PRIVILEGES");
}
}
else
{
my $tmp = $disc_quota{$data->{name}};
my $sth2 = $dbh->prepare('update hpersons set quota = ? where name = ?');
$sth2->execute($tmp->{used},$data->{name});
$count++;
}
}
}
trace("End disk_usage_mysql_quota [ ***** ]");
$dbh->disconnect;
$dbh1->disconnect;
#unlock();
sub trace
{
my $msg = shift;
warn "[ ".localtime()." ] $msg \n";
}
#print $count0."\n";
#print $count."\n";
#print $count1."\n";
#print $count2."\n";
#print $count3."\n"