Scott
Scott

Reputation: 11206

Apache Log rotation Script

I have the following script running to backup my apache logs

#!/bin/sh
dt=`date +%m%d%Y`
cp /var/log/httpd/domainname/www/error_log /var/log/httpd/domainname/www/oldlogs/error_log$dt
cat /dev/null > /var/log/httpd/domainname/www/error_log
cp /var/log/httpd/domainname/www/access_log /var/log/httpd/domainname/www/oldlogs/access_log$dt
cat /dev/null > /var/log/httpd/domainname/www/access_log

Which is scheduled via cron. So each night the logs get backed up and emptied. However, the next morning I always get files with weird characters after the date

[me@computer oldlogs]# ls
access_log07202009??  access_log07212009??  error_log07202009??  error_log07212009??

[me@computer oldlogs]#cat access_log072
access_log07202009^M^Maccess_log07212009^M^M

and I'm unable to find what is causing it. Any idea?

Upvotes: 2

Views: 1865

Answers (2)

paxdiablo
paxdiablo

Reputation: 882586

I'd be checking:

  • the ${dt} variable from within the cron job (echo "${dt}" | od -xcb >/tmp/qq); and
  • the actual script itself (od -xcb scriptname);

to see if there's weird characters being generated anywhere.

Also, I can't figure out your second command. Is there an access_log072 file there somewhere or was your command truncated somehow?

Upvotes: 1

Javier
Javier

Reputation: 62671

logrotate is your friend

Upvotes: 2

Related Questions