I have an hourly cron script which take some output (a mysql dump), pipes it through gzip, and aims to overwrite a file of the same name. When I run it manually as root
the file is overwritten. When it is ran by the cron daemon the filename has ".1" appended to it. This keeps happening so that after a while I have lots of files like so:
myfile.gz
myfile.gz.1
myfile.gz.1.1
myfile.gz.1.1.1
myfile.gz.1.1.1.1
and so on.
ps aux|grep crond
shows that the daemon is being run as root
.
I've tried:
- renaming the original file, pushing the output, then removing the old file on completion, and
- deleting the original file before piping the output
but neither works as expected and I just get .1.1.1.1
files.
Script looks like this (nothing special) and is located on a CentOS box in /etc/cron.hourly
:
#!/bin/bash
DATE=`date +%H`
DIR="/abs/path/to/dir"
FILE="hourly-${DATE}.gz"
OPTS="..."
mysqldump $OPTS | gzip -9 > $DIR/$FILE
Can anyone advise as to why this simple operation isn't running as expected?