I am making backups of all databases of MySQL into separate gnu-zip files using crontab. I also want to delete backup files older then 1 day.
I am using below command to delete the old files, but it only works through terminal. If I set cronjob for same command then it does not work. I don't know what is wrong. Going on my command is below:
find path -type f -mtime +0 -delete
I also can't find any fault in setting up cronjob:
0 0 * * * /path/auto_delete_backup_database.sh >/path/auto_delete_backup_database.log
any help will be appreciated.
UPDATE
as @Kusalananda mentioned i ran ls -l
and result is as displayed in below screen shot
So is it because .sh file does not have required permission to be executed? if so, how can I grant that permission?
2>&1
to the cron entry so that errors are captured too – Chris Davies Dec 21 '19 at 09:50ls -l /path/auto_delete_backup_database.*
– Chris Davies Dec 21 '19 at 09:51/path/auto_delete_backup_database.sh
(un-generalised: so no,path
show the path. I fear that you have generalised away the error). – ctrl-alt-delor Dec 21 '19 at 11:042>&1
in cronjob after .sh or after .log ? and what willls -l
will do – Divyang patel Dec 27 '19 at 10:222>&1
at the very end. Thels -l
will show whether the script file is executable or not. Does the script have a#!
-line pointing to some shell? Is it doing anything else than running thefind
command? – Kusalananda Dec 27 '19 at 10:31#!
shell specification. – Divyang patel Dec 27 '19 at 10:36