I have a cron job that runs a shell script. The contents of the shell script is as follows:

sudo service confluence stop

NOW=$(date +"%Y%m%d-%H%M%S")

mkdir Backup/db
mkdir Backup/data
chmod 777 Backup/data/

sudo -u postgres pg_dump confdb > Backup/db/confdb-$NOW.sql
sudo -u confluence cp -r /var/atlassian/application-data/confluence/ Backup/data/
sudo chown -R backupuser:backupuser Backup/data/confluence
tar czvf Backup/confluence-backup-$NOW.tgz Backup/db Backup/data
rm -rf Backup/data/ Backup/db/
rsync --remove-source-files -v Backup/*.tgz CloudBackup/
find CloudBackup/ -type f -mtime +30 -delete
sudo service confluence start

The CloudBackup folder is mounted in my /etc/fstab as follows:

//mediaserver/shared/AmazonCloudDrive/Backup/confluence /home/backupuser/CloudBackup cifs uid=backupuser,credentials=/home/backupuser/.smbcredentials,iocharset=utf8,sec=ntlm 0 0

The only part of the shell script that doesn't work when it is run by the cron job is the find CloudBackup/ -type f -mtime +30 -delete command. However, if I log into the console and run the script as the same user that's running the cron job, everything works and the files get deleted.

Can anyone explain why everything works when the script is run from the console but the find command doesn't work when the script is run as part of a cron job by the same user?

  • can you check your $PATH? Also try with the fill path of the CloudBackup folder? For debug, you can just run find CloudBackup/ -type f -mtime +30 -print in the cron the see what happens. – Tux_DEV_NULL Nov 20 '17 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.