using cron job to copy access logs
Posted by: anks329
Posted on: 2005-12-30 19:16:00
I'm trying to set up a way to automatically copy my access logs to a backup folder so that I don't lose them. So far, I've managed to create a script that copies access.log.0 into a different folder and then adds the current date to the end of it. It works fine when i run it from the shell. So the next step was the automate with a cron job. The cron job copied the files, but didn't rename them correctly.
Here is the code for script (its called script1.sh):
#!/bin/bash
# Set today's date variable in yyyymmdd format
set tdy=`date %Y%m%d`
#copy the logs
cp logs/anksconsulting.com/http/access.log.0 ~/lgbackup
cp logs/anksconsulting.com/http/error.log.0 ~/lgbackup
# rename the logs
mv lgbackup/access.log.0 lgbackup/access.log.$tdy
mv lgbackup/error.log.0 lgbackup/error.log.$tdy
unset tdy
and then the cron job calls the script as follows:
0 19 * * * /home/[username]/script1.sh
any suggestions as to what I should do to fix this?
Edited by anks329 on 12/30/05 07:16 PM (server time).