[FreeBSD 5.2.1] Giving dynamic filenames

Glaanieboy

OSNN Veteran Addict
Joined
6 Mar 2002
Messages
2,628
I want to create a script (along with a daily/weekly cronjob), that does the following to the httpd (apache) logs:
  • Rename the logs
  • Create a new, empty log file by using touch <filename>
  • Move the backup file to a directory, for example a dir in my own home dir
This is basically it, but I have a problem/question about the first part: As you probably have read, I want to use this script with a daily/weekly cronjob, so I get the apache logs sorted daily/weekly. In order to tell them apart, I want to add a dynamic extension to the filename, like httpd-access.log.2004-9-26, or httpd-access.log.2004-<weeknumber>, but how can I create a dynamic filename like that? Can I do that in the script? How?

Btw, I created a part of the script, which is like:
Code:
cd /var/log/httpd
;**This is where I want the dynamic extension. In this example
;**I used .bck at the end of the filename,
;**but I want this to be dynamic.
mv httpd-access.log /path/to/archive/httpd-access.log.bck && touch httpd-access.log
mv httpd-error.log /path/to/archive/httpd-error.log.bck && touch httpd-error.log

Thanks :)
 
Consider this thread obselete, I was just browsing the internet about totally unrelated matters and I found it:
mv httpd-access.log httpd-access.log.`date +%Y-%m-%d`
(will give you something like httpd.access.log.2004-09-26)

:eek:

Close this please.

Btw, I promise I'll try to search longer before I ask my question here...
 
I think you can set that up in the httpd.conf file as well
 
Hmm, maybe I'll do that later. Anyway, I have a cronjob running at every monday 0:01 hours, using the script I just created, so that's ok too.
 
I'm not a BSD person ... but wouldn't logrotate pretty much do the same thing?
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back