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):
Set today’s date variable in yyyymmdd format
#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
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?