• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

[FreeBSD 5.2.1] Giving dynamic filenames

#1
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 :)
 
#2
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...
 
#4
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.
 

Members online

No members online now.

Latest posts

Latest profile posts

Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,014
Latest member
sanoravies