I have created a bash script.
#!/bin/bash
now=$(date %Y-%m-%d--%H:%M:%S)
mysqldump -uMYUSER -pMYPASSWORD MYDB --no-tablespaces | gzip > ./files/$now.sql.gz
I am trying to run it with a crontab once a day. I typed crontab -e and pasted this:
# m h dom mon dow command
0 0 * * * /bin/bash ~/backup/script.sh
I can run the script as-is, but the script never runs by itself.
CodePudding user response:
- try to run crontab with root user (sudo crontab -e) ,
- locate script in root user folder ~/backup/script.sh
CodePudding user response:
Suggesting to fix your script:
Inject 2nd line with source to current .bash_profile
This will included environment context and path to your cron script.
sed -i "source $HOME/.bash_profile" <your_script>
