Good day.
There is a script to backup MySQL databases and upload to Yandex disk:

#/usr/bin/bash # шифрование файла GPG_COMMAND="gpg -c -z 0 --no-batch --passphrase 123" MYSQL_FILE=database_backup_`date +%d_%m_%Y_%H_%M_%S`.sql.gz.gpg # бэкап бд mysqldump -u root -padmin --events --ignore-table=mysql.event -h 127.0.0.1 --all-databases | gzip | $GPG_COMMAND> /var/www/mysql_backups/$MYSQL_FILE # если бэкап не создался if [ ${PIPESTATUS[0]} -ne "0" ] then echo ERROR MYSQL DUMP # отправить смс curl -d "text=Error backup all-databases." http://sms.ru/sms/send\?api_id=11111-5A6D-34545-CE5E-111\&to=380631111111 # отправить эл. письмо echo "Error backup all-databases." | mail -s "Error mysql dump" example@example.ru exit 1 else echo GOOD MYSQL DUMP # отправить с помощью curl на яндекс диск и записать статус в RESPONSE_STATUS RESPONSE_STATUS=$(curl --user login:password -T /var/www/mysql_backups/$MYSQL_FILE https://webdav.yandex.ru/backup_ubuntu_mysql/ -sw '%{http_code}' -m 100) # если вернулся статус 201, значит закачалось удачно if [ $RESPONSE_STATUS == 201 ] then echo GOOD PUSH YANDEX echo GOOD BACKUP # удаляем бэкап из локальной папки unlink /var/www/mysql_backups/$MYSQL_FILE exit 0 # если не закачалось, отправляем смс и эл. письмо else echo BAD PUSH YANDEX curl -d "text=Error upload backup to Yandex Disk. Response Status Code != 201." http://sms.ru/sms/send\?api_id=111-444-8059-CE5E-5DSFDS8A8\&to=380631111111 echo "Response Status Code != 201." | mail -s "Error upload backup all-databases to Yandex Disk" example@example.ru exit 1 fi fi 

If I run in Ubuntu 14.04 through the terminal ./all_database.sh , the script works successfully, i.e. A backup is created and poured onto the Yandex disk:

enter image description here

And if I add a task to the crontab:

enter image description here

That script does not work out completely. That is, a dump is created and all. On Yandex disk file is not poured. And to look in some logs, for example, I can not, in and what caused the snag. I gave the file the right chmod 777 , but it still does not fully work, although if the problem would be in the rights, then the dump would not have been created.
Please tell me what could be the problem?

  • one
    well so on, on behalf of what user the script is launched in krone? From root, from you, from local usernames. Look here. In general, the steps can be echo crammed as a debug, and see what the mail will come - maint
  • Add echo $RESPONSE_STATUS and see what it returns. - MANK
  • You hide your uid from sms ru;) - Smithson

1 answer 1

I added the phrase bash before the path to the script in the crontab (crontab -e), and now the script is executed fully automatically. Thank you all) Example below:

 01 00 * * * bash /home/andrey/backup_scripts/all_database.sh 
  • As an alternative, change the first line to #!/usr/bin/bash (you now have no exclamation mark). If your bash is valid in / usr / bin, not / bin. - MANKK