a scriptet itt a forumon talaltam meg regen, en csak belebarkacsoltam, hogy kiket listazzon, mert alapbol mindenkit kuldott, meg hozzaadtam a tarhelyet is, ha mar jon mail nem art ha latom, hogy esetleg lassan megtelik a hattertar...
Amit meg tudni erdemes az az, hogy a traffic limitet en nem hasznalom igy mikor beleturtam nem figyeltem ra, hogy az is mukodjon, ezert nem is megy, szoval ha kell valakinek akkor vagy szoljon vagy irja at kicsit
disk-usage-report.pl
Code:
#!/usr/bin/perl
#
# Generates a report of disk and traffic usage of all ispCP domains
#
use strict;
use warnings;
use DBI;
use Time::Local;
#
# Configuration
#
# Notice-Limit in percent; a notice is added to a domain if it uses more percent of its disk or traffic limit than this value
my $notice_limit = 90;
# MySQL-Hostname (default: localhost)
my $db_host = "localhost";
# MySQL-Database name (default: ispcp)
my $db_name = "ispcp";
# Username and password for a MySQL-User which is allowed to query the ispcp database
my $db_user = "DBUSER";
my $db_pass = "DBPASS";
#
# End of Configuration
#
# Connect to the database
my $dbh = DBI->connect("DBI:mysql:database=$db_name;host=$db_host", $db_user, $db_pass)
or die "Can't connect to the database: $DBI::errstr\n";
# Retrieve all domains
my $query = $dbh->prepare("SELECT domain_id, domain_name, IFNULL(domain_disk_usage,0), IFNULL(domain_disk_limit,0), IFNULL(domain_traffic_limit,0) FROM domain where ((domain_disk_limit*1024*1024)<(domain_disk_usage+(domain_disk_limit*1024*1024*0.05))) and domain_disk_limit>0 ORDER BY domain_name");
$query->execute()
or die "Can't execute query: $DBI::errstr\n";
# Go through all domains and generate the report
my $report = "";
while (my ($id, $name, $disk_u, $disk_l, $traffic_l) = $query->fetchrow_array ) {
# Get currently used traffic (from 1st of this month till today)
my ($mon,$year) = (localtime())[4..5];
# Correction, see http://perldoc.perl.org/functions/localtime.html
$year += 1900;
# Generate UNIX-Timestamp for the 1st of this month
my $begin = timelocal(0,0,0,1,$mon,$year);
# Query the database
my $traffic_query = $dbh->prepare("SELECT IFNULL(sum(dtraff_web), 0), IFNULL(sum(dtraff_ftp), 0), IFNULL(sum(dtraff_mail), 0), IFNULL(sum(dtraff_pop), 0) "
. "FROM domain_traffic WHERE domain_id = $id AND dtraff_time >= $begin AND dtraff_time <= " . time());
$traffic_query->execute()
or die "Can't execute query: $DBI::errstr\n";
my ($web, $ftp, $mail, $pop) = $traffic_query->fetchrow_array;
# Calculate currently used disk space and traffic in MB
my $traffic_u = ($web + $ftp + $mail + $pop) / ( 1024 * 1024 );
$disk_u /= (1024 * 1024);
# Create the sub-reports
my $notice = "";
$notice .= " (*High disk usage*)"
if ($disk_l != 0 && 100*$disk_u/$disk_l > $notice_limit);
$notice .= " (*High traffic usage*)"
if ($traffic_l != 0 && 100*$traffic_u/$traffic_l > $notice_limit);
my $disk_report = "Disk usage: " . sprintf("%.2f", $disk_u) . " MB / " . ( ( $disk_l == 0 ) ? "unlimited" : "$disk_l MB (" . sprintf("%.2f", 100*$disk_u/$disk_l) . " %)" );
my $traffic_report = "Traffic usage: " . sprintf("%.2f", $traffic_u) . " MB / " . ( ( $traffic_l == 0 ) ? "unlimited" : "$traffic_l MB (" . sprintf("%.2f", 100*$traffic_u/$traffic_l) . " %)" );
# Write the report line
$report .= "$name:$notice\n\t$disk_report\n\t$traffic_report\n\n";
}
# Close database connection
$dbh->disconnect;
# Get Date
my ($day, $month, $year) = (localtime)[3,4,5];
my $today = sprintf("%d-%02d-%02d", $year+1900, $month+1, $day);
# Print the report
print "=== ispCP - Domain Disk and Traffic Usage Report ($today) ===\n\n";
print $report;
exec "df -h";
crontab
Code:
0 6 * * * root /path/to/the/script/disk-usage-report.pl | mutt -s "ispCP Server - Domain Disk and Traffic Usage Report" your@email.address