Perl 程式如下,把程式加到 crontab 內,即可自動檢查 log 檔,大於一定程度後,執行備份壓縮並把log清空
#!/usr/bin/perl
$now = `date +%Y%m%d_%H%M`;
chomp($now);
$logname = "$now".".tgz";
#User Define
#50MB
$logsize = "51200k";
#monitor log path or file
$logpath = "/oracle/admin/IMSBKDB/bdump/alert_IMSBKDB.log";
$found = `/usr/bin/find $logpath -size +$logsize -print`;
chomp($found);
if ($found) {
print "$found => tar\n";
#alert_IMSBKDB.log bigger than 50MB, backup and cp /dev/null for it
`/usr/bin/find $logpath -size +$logsize -exec /bin/tar zcvf /oracle/admin/IMSBKDB/bdump/backup/$logname {} \\;`;
sleep 1;
`cp /dev/null $logpath`;
} else {
print "do nothing\n";
}
沒有留言:
張貼留言