zabbix:/root/sbin# perl t1.pl 20160101 20160105
create table test1.test_20160101;
create table test1.test_20160102;
create table test1.test_20160103;
create table test1.test_20160104;
create table test1.test_20160105;
create table test2.test_20160101;
create table test2.test_20160102;
create table test2.test_20160103;
create table test2.test_20160104;
create table test2.test_20160105;
create table test3.test_20160101;
create table test3.test_20160102;
create table test3.test_20160103;
create table test3.test_20160104;
create table test3.test_20160105;
zabbix:/root/sbin# cat t1.pl
use DBI;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
my $ip="127.0.0.1";
my $user="root";
my $passwd="1234567";
my $dbh = DBI->connect("dbi:mysql:database=$message;host=$ip;port=3306",$user,$passwd) or die "can't connect to database ". DBI-errstr;
##防止utf-8中文乱码
$dbh->do("SET NAMES utf8");
my $date1= "$ARGV[0]";
my $date2="$ARGV[1]";
my $date=$date1;
my $tip='+1';
sub get_date{
my $var_date=$_[0];
my $hostSql = qq{ SELECT DATE_FORMAT( DATE_ADD( '$var_date', INTERVAL $tip DAY), '%Y%m%d') AS xxx FROM information_schema.tables a limit 1;};
my ($a1, $a2, $a3,$a4,$a5,$a6,$a7,$a8,$a9);
my $selStmt = $dbh->prepare($hostSql);
$selStmt->execute();
while (@recs=$selStmt->fetchrow_array) {
foreach (@recs)
{$date=$_;return $date}
};
};
for ($i=1;$i<=3;$i++){
while (1==1){
$date3=$date;
print "create table test$i.test_$date3;
";
$date=&get_date($date3);
if ( "$date" == "$date2" ){print "create table test$i.test_$date;
";$date="$date1";last;}
};
};