I am trying to schedule some backup scripts in cron on a CentOS release 6.7 (Final).
This is the full backup, basically mounts a remote directory, checks if there is enough space available for doing the backup (it does it if the disk is at 85% or less), finally sends a mail for report and dismounts the directory
The script is located in /root/myjobs/
and its named fullbackup.sh
The permissions are 777 (-rwxrwxrwx) for now
#!/bin/bash
mount -t cifs //192.168.0.202/Volume_1 /mnt/nas -o username=Backup,password=PassBackup
ocupado="$(df /mnt/nas|tail -n 1|awk '{print $4}'|cut -d "%" -f 1)"
if [ $ocupado -gt 85 ]; then
echo "DISK IS FULL" | mail -s "SERVER" [email protected]
else
# This is anoying but at least works, I need to create a file with the name of the backup, delete it, and then make the backup with tar
touch /mnt/nas/Backup/full_backup_`date +"%d%b%y"`.tar.gz
rm -f /mnt/nas/Backup/full_backup_`date +"%d%b%y"`.tar.gz
tar -cvzpf /mnt/nas/Backup/full_backup_`date +"%d%b%y"`.tar.gz --exclude=/home/general /home
echo "FULL BACKUP OK" | mail -s "SERVER" [email protected]
fi
umount /mnt/nas/
If I run the script manually it works fine, but if I schedule the script with cron it only sends the mail,but does not make the copy, like it does not execute the tar command.
If I execute crontab -e
I see the nano editor, with this path in the top:
/tmp/crontab.jdwF9c
I think something is wrong with the path, that's why I am configuring cron editing the /etc/crontab
file directly.
This is my /etc/crontab
file:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
0 9 1 * * root /root/myjobs/fullbackup.sh
I have translated this question of Spanish as best I could, I hope the problem is well understood.
Thanks for your help!
EDIT 1: I interact with the server remotely. The cron runs the script and works correctly when I'm connected, but not if I close the ssh connection and I wait for the command to run at 9:00 the next day. In that case only sends the mail.
crontab -e
creates a temporary copy of your crontab for you to edit which it then installs for you. The path/tmp/crontab.jdwF9c
is not an issue.getenforce
. Just asking because I've been permanently traumatized by the ways of SELinux can jump in front of you making things harder. Extra security is good, but the extra hassle it can cause can be painful.