I need more information, exactly on what you want... like... what you have access to all. Let me put it this way, if you want to give me the paths to the log files, and the paths to where you want them saved, I'll build it for you. I'm not 100% sure about the zipping.... I know I could tar them, but tarring individual files? I am sure I could bzip it or something..... let me know, my e-mail is available on this site by clicking my name, and following the menus.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
Yes. Truth is, it's already done, and he's already using it. I coded it, and commented it line by line, so he could learn from and modify it for future needs.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
Someone E-mailed Me, Requesting The Source For This, So, Here is the actual script (with modified paths for privacy):
#!/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";
}
}
}
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
Yes, It Is A Perl Forum.... But Nice Script.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215