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.
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.