• 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

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:
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)

Close this please.

Btw, I promise I'll try to search longer before I ask my question here...
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 ...
What a long strange trip it's been. =)

Forum statistics

Latest member