I have a cron job that runs a shell script. The contents of the shell script is as follows:
#!/bin/bash cd 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
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?