I have a script called backup.sh
:
#!/bin/bash
sudo zip -r /home/jazuly/backup.zip /var/lib/automysqlbackup/
cd /home/jazuly/backupscript/cp2google/
php cp2google.php /home/jazuly/backup.zip
cd ~
rm -f /home/jazuly/backup.zip
I made it executable:
sudo chmod +x backup.sh
Then I tried to edit cron
with crontab -e
.
I add:
# m h dom mon dow command
0 0 * * * /home/jazuly/backup.sh
but when cron
sends the backup.zip to my email, I download and open it, and the file is corrupt.
If I run the script manually with:
$ sudo chmod +x backup.sh
$ ./backup.sh
I can open the zip file.
/home/jazuly/backup.zip
as root (sudo
) and then try to delete it as a regular user (rm -f /home/jazuly/backup.zip
), that doesn't make sense. – terdon Jun 15 '17 at 08:46whereis -b zip
– zombic Jun 15 '17 at 08:56zip -T
before sending to php script. and again echo zip file size from php script. cron should report output. Debug your problem in this way. Figure out at what point it breaks.My guess is it's your php script or way its called from bash. Or not giving php binary a full path when called from cron. Use full paths – B. Shea Jun 16 '17 at 04:07