Why Cron works, but nothing happens when launch bash script?
Why Cron works, but nothing happens when launch bash script?
I created bash script "auto-gzip.sh" to zip my public files:
Added this file to cron via Vesta interface:
Try this command manually - it works good. But it doesn't work via Cron although logs are added every minute:
So, Cron works, but nothing happens. Why?
Code: Select all
#!/bin/bash
cd /home/admin/web/site.com/public_html/
find . -name "*.gz" -type f -delete
gzip -kfr --best .
Code: Select all
sudo bash /home/admin/web/site.com/scripts/auto-gzip.sh
Code: Select all
Jun 17 09:11:01 source CRON[6307]: (admin) CMD (sudo bash /home/admin/web/site.com/scripts/auto-gzip.sh)
Re: Why Cron works, but nothing happens when launch bash script?
Quite often problems with cron are down to not finding the correct paths for executables. Try to specify the full path to find and gzip for a start.
~$ which gzip
/bin/gzip
~$ which find
/usr/bin/find
So ...
I'd also suggest not storing the gz file in the web root as that's publicly accessible.
You might also try adding the cron job not using the vesta cron interface (which will run the commands with sudo), but by ssh-ing into the server and using 'crontab -e'. You'll see all the vesta cronjobs at the top. You can just add yours at the bottom:
# My cronjobs:
30 11 * * * /home/admin/path/to/script/backup.sh > /dev/null 2>&1
~$ which gzip
/bin/gzip
~$ which find
/usr/bin/find
So ...
Code: Select all
cd /home/admin/web/site.com/public_html/
/usr/bin/find /home/admin/web/site.com/public_html/ -name "*.gz" -type f -delete
/bin/gzip -kfr --best .
You might also try adding the cron job not using the vesta cron interface (which will run the commands with sudo), but by ssh-ing into the server and using 'crontab -e'. You'll see all the vesta cronjobs at the top. You can just add yours at the bottom:
# My cronjobs:
30 11 * * * /home/admin/path/to/script/backup.sh > /dev/null 2>&1