#!/usr/bin/perl
# The Line Above Might Need To Be Changed To Wherever Perl is Located
#################################
# Custom Defined User Variables #
#################################
$logpath = "/home/sites/path2your/logs";
$orgfile1 = "youraccess_log";
$orgfile2 = "cabmirror.youraccess_log"; # Assuming You Have A Mirror Log
$use_rename = "true"; # Rename The Original Logfile After The Date is Added?
$use_zip = "true"; # Use Zip Compression On The Renamed Logfiles?
$remove_original_after_zip = "true"; # Remove The Orignal Logfile AFTER it has been zipped? # Or Have a logfile, and a zipped logfile?
###################################
# End of Custom Defined Variables #
###################################
# /* Get The Formated Date For Today */
$today = &get_todays_date;
# /* If We Are Renaming The Original Log File */
if ($use_rename eq "true") {
# /* Call Sub-Routine To Rename Log File */
&rename_logfile;
} else {
# /* Call Sub-Routine To Xerox Log File With New Name */
&xerox_logfile;
}
# /* If We Are Going To Zip The Log Files */
if ($use_zip eq "true") {
# /* Call The Sub-Routine To Zip Logfiles of "Today" */
&zip_logfiles;
}
# /* Stop This Program From Running */
exit;
sub get_todays_date
{
# /* Get The Current Date (Open As A new Thread) */
open(DT, "date +\%D |");
# /* Store The Date In Variable $rawdate, and remove any new line characters */
chomp($rawdate = <DT>);
# /* Close The "Date" Process */
close(DT);
# /* Rip Apart The Raw Date Into Respective Parts */
($month, $day, $year) = split(/\//, $rawdate);
# /* Format The Parts Of The Date Into Our Desired Format */
$good_date = "20$year-$month-$day";
# /* Return The Formated Date Back To Our Main Program From This Sub */
return $good_date;
}
sub rename_logfile
{
# /* If The First Logfile Exists, Then Archive It, Otherswise Do Nothing */
if (-e "$logpath/$orgfile1") {
# /* Rename The Original File To The New File With The Appended Date */
`mv $logpath/$orgfile1 $logpath/$orgfile1.$today`;
}
# /* If The Second Logfile Exists, Then Archive It, Otherwise Do Nothing */
if (-e "$logpath/$orgfile2") {
# /* Rename The Original File To The New File With The Appended Date */
`mv $logpath/$orgfile2 $logpath/$orgfile2.$today`;
}
}
sub xerox_logfile
{
# /* If The First Logfile Exists, Then Archive It, Otherswise Do Nothing */
if (-e "$logpath/$orgfile1") {
# /* Copy The Original File To The New File With The Appended Date */
`cp $logpath/$orgfile1 $logpath/$orgfile1.$today`;
}
# /* If The Second Logfile Exists, Then Archive It, Otherwise Do Nothing */
if (-e "$logpath/$orgfile2") {
# /* Copy The Original File To The New File With The Appended Date */
`cp $logpath/$orgfile2 $logpath/$orgfile2.$today`;
}
}
sub zip_logfiles
{
# /* If The Logfile With Appended Date Exists */
if (-e "$logpath/$orgfile1.$today") {
# /* Add The Logfile To It's Own Zip Acrchives */
`zip $logpath/$orgfile1.$today.zip $logpath/$orgfile1.$today`;
}
# /* If The Logfile (With Appended Date) Exists */
if (-e "$logpath/$orgfile2.$today") {
# /* Add The Logfile To It's Own Zip Archive */
`zip $logpath/$orgfile2.$today.zip $logpath/$orgfile2.$today`;
}
# /* If We Are Going To Remove The Original Logfile (Not The Zip) After it's been Zipped */
if ($remove_original_after_zip eq "true") {
# /* If The First Logfile (Uncompressed) Exists */
if (-e "$logpath/$orgfile1.$today") {
# /* Then Delete The File (The Uncompressed Logfile, Not The Zip) */
unlink "$logpath/$orgfile1.$today";
}
# /* If The Second Logfile (Uncompressed) Exists */
if (-e "$logpath/$orgfile2.$today") {
# /* Then Delete The File (The Uncompressed Logfile, Not The Zip) */
unlink "$logpath/$orgfile2.$today";
}
}
}