Server Administration
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Codewalkers ForumsOther TechnologiesServer Administration

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Old August 11th, 2003, 02:58 PM
Jester Jester is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: England
Posts: 271 Jester User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Apache2 - pipe logs and cron?

Hi,

I'm looking at my log configuration set-up within Apache2. Currently I am utilising the piped logging facility in the following way:

# The format for logging the three different custom logs: common, referer and agent
LogFormat "%h,%l,%u,%t,"%r",%>s,%b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Put all logs on a piped logging rotate routine

# General Apche error log on a 1 week rotate, saved to /etc/apache2/logs/error.YYYYMMDD.log
ErrorLog "|/etc/apache2/bin/rotatelogs /etc/apache2/logs/error.%Y%m%d.log 604800"

# Custom logs on a 1 week rotate, saved to /etc/apache2/logs/[log name].YYYYMMDD.log
CustomLog "|/etc/apache2/bin/rotatelogs /etc/apache2/logs/access.%Y%m%d.log 604800" common
CustomLog "|/etc/apache2/bin/rotatelogs /etc/apache2/logs/referer.%Y%m%d.log 604800" referer
CustomLog "|/etc/apache2/bin/rotatelogs /etc/apache2/logs/agent.%Y%m%d.log 604800" agent

This works well, and within my log folder in the web space I get a new log each week. However, what I would like to do is just keep the newest two (i.e. the current log, and the previous log). Any other logs should be gzipped and move to a sub folder within the log folder.

Has anyone any idea on the best way to do this? I know that you can use cron for jobs like this, and I have looked at the tutorial on this site, but am still unsure on how to start. There are also specific folders on my Suse 8.2 installation like /etc/cron.weekly,is there some sort of script that I could drop in there?

Any ideas or pointers in the right direction would be brill,

Thanks, J

Reply With Quote
Old August 12th, 2003, 12:59 AM
postalcow postalcow is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Ford CIty, PA USA
Posts: 1,267 postalcow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via Yahoo to postalcow
RE: Apache2 - pipe logs and cron?

I read through your post a couple of times. I am having a little trouble getting a grasp on what you want. So your OK with your logs being written you just want to tarball/gzip all but the two newest ones correct?

If correct I do something similar. I wrote a PHP script that does a backup everyday gzips um then deletes the the ones more than 5 days old. This script could easily be modified to do what you want if I understand correctly

Reply With Quote
Old August 12th, 2003, 09:50 AM
Jester Jester is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: England
Posts: 271 Jester User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
RE: Apache2 - pipe logs and cron?

Yep - that's about the long and short of it! Thanks for your time.

Thought I would have to use cron and some weird coding - but much rather use PHP and trigger with cron!

Could you point me in the direction of the code?

J

Reply With Quote
Old August 12th, 2003, 05:58 PM
postalcow postalcow is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Ford CIty, PA USA
Posts: 1,267 postalcow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via Yahoo to postalcow
RE: Apache2 - pipe logs and cron?

Are you going to rewrite my script yourself?

Reply With Quote
Old August 13th, 2003, 09:41 AM
Jester Jester is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: England
Posts: 271 Jester User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
RE: Apache2 - pipe logs and cron?

Sorry postalcow - I just assumed that you wouldn't mind! If it's copyrited etc then no prob, just post the pseudo code for me and I'll try to work it out! (I assume that it's phpcl that you trigger by cron? Never done this so do you think you could also show me how to get the script to run each week?!)

I hardly ever just blindly use other's code though - I always use it as a base, research what each part does (if I don't already know) and then write my own.

That is the way I learn (can't just look and have it stay in my head - gotta do it myself to remember :laugh: !!!)

J

Reply With Quote
Old August 18th, 2003, 09:54 AM
Jester Jester is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: England
Posts: 271 Jester User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
RE: Apache2 - pipe logs and cron?

Sorry for the bump postalcow - but is there any chance of seeing that code? Pretty please?!!!

J

Reply With Quote
Old August 18th, 2003, 12:33 PM
postalcow postalcow is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Ford CIty, PA USA
Posts: 1,267 postalcow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via Yahoo to postalcow
RE: Apache2 - pipe logs and cron?

No problem on the bump. I am the one that forgot, sorry. Is something like this what you wanted? Just put the script in a location like /usr/local/util and fire it daily by cron.
php Code:
Original - php Code
  1. #!/usr/bin/php -q
  2.  
  3. <?
  4. // Above set path to php
  5.  
  6. // I use epoch there are many ways to do time calculations. Some are better some are worst
  7. // This is how I do it. Also there are PHP commands for copy and mkdir I just use the unix
  8. // commands here. This is a hack way to do it but it does work. Others may post better ways
  9. // of doing this
  10. // I seperated everything so it is easier to follow what I am doing
  11.  
  12. $epoch = date(U);
  13. $today = date("Ymd", $epoch);
  14. $backup_path="/backup/path";
  15. $calc_del = ($epoch -432000); // Number of days in seconds to delete 432000 is 5 days
  16.  
  17. $delete = date("Ymd", $calc_del);
  18.  
  19. // If you need to create a DIR for backups
  20.  
  21. exec("mkdir $backup_path/$today");
  22.  
  23. // you could also pre note the dir it creates like this
  24. // exec("mkdir $backup_path/logs$today");
  25. // this will give you a dir of logs20030818
  26.  
  27. // Tarball the file in your backup dir
  28. // * is all in that dir you can set specific files
  29. // I put them in a directory w/todays date formatted so they remain sequential
  30.  
  31. // Add as many tarball's as you like
  32.  
  33. exec("tar -cvf $backup_path/$today/somefile.tar /var/log/httpd/*");
  34.  
  35.  
  36. // gzip all the files
  37. exec("gzip $backup_path/$today/*");
  38.  
  39. // this will delete directorys older that 5 days you can delete anything you want
  40.  
  41. exec("rm -rf $backup_path/$delete");
  42.  
  43. // This is a simple way of doing things but it does work. Is this what you wanted?
  44.  
  45.  
  46. ?>

Reply With Quote
Old August 19th, 2003, 10:34 AM
Jester Jester is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: England
Posts: 271 Jester User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
RE: Apache2 - pipe logs and cron?

More than I expected - it's nice to see someone taking the time to comment rather than pasting up 'black art' code!

Comments allow people to take the 'idea' of the code and apply it in thier own style and situation, rather than copy and paste without any learning or understanding - thank you and long may this ethos continue on codewalkers!

J

Reply With Quote
Old August 19th, 2003, 10:49 PM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
RE: RE: Apache2 - pipe logs and cron?

Quote:
More than I expected - it's nice to see someone taking the time to comment rather than pasting up 'black art' code!


i am more than guilty for this..

i'll do my best to try to correct it ;)

Reply With Quote
Old August 19th, 2003, 11:01 PM
postalcow postalcow is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Ford CIty, PA USA
Posts: 1,267 postalcow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via Yahoo to postalcow
RE: Apache2 - pipe logs and cron?

I do it too often myself.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesServer Administration > Apache2 - pipe logs and cron?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap