Cron won't execute if am not logged in

Posted by JonaMX on Ask Ubuntu See other posts from Ask Ubuntu or by JonaMX
Published on 2013-10-25T15:07:04Z Indexed on 2013/10/30 16:12 UTC
Read the original article Hit count: 212

Filed under:
|

I have a cron that makes a backup of MySql, if I execute on shell it works pretty well even if I'm logged when cron supposed to execute works fine, but if I'm not logged just won't execute, I don't know what could happened, any suggestion ?

Crontab

00 04 * * * /home/administrador/scripts/respaldo.sh

respaldo.sh

#!/bin/sh
mysql -uroot -p[PASS] ccs < /home/administrador/scripts/limpia.sql
mysqldump -uroot -p[PASS] --routines ccs > /home/administrador/backups/backup_$(date +%Y%m%d).sql
mysqlcheck -uroot -p[PASS] --auto-repair --optimize  ccs
cd /home/administrador/backups/
tar -zcf backup_$(date +%Y%m%d).tgz backup_$(date +%Y%m%d).sql
rm backup_$(date +%Y%m%d).sql
find -name '*.tgz' -type f -mtime +90 -exec rm -f {} \;

respaldo.sh has execute permission

SOLUTION

The problema was that the /home/adminsitrador directory was an encrypted folder so when the user is logged in the folder it's decrypted and everything works but when the user it's logged off the folder it's encrypted and the cron can't access to that path, so I've changed the cron script and backup to another unencrypted folder and to root user and now everything it's working pretty well, thanks to all for your help !

© Ask Ubuntu or respective owner

Related posts about encryption

Related posts about cron