问题
I was having the same issue as this person and this person, where my command worked locally but inside of a cron task, nothing happened.
Here is what I am trying to run:
/usr/bin/mysqldump -u root -ppassword database_name > ~/Documents/dump.sql
This works locally when I type I straight into my terminal! It might throw an error saying:
mysqldump: [Warning] Using a password on the command line interface can be insecure
But it still it works. It even works if I put in the user root
before the command.
Now, here is the CRON (just trying to run it every minute to test if it works)
*/1 * * * * root /usr/bin/mysqldump -u root -ppassword database_name > ~/Documents/dump.sql
And... nothing happens. What I saw from this question and [this person] was that it was a matter of syntax. I cannot figure out WHY this CRON will not run!
回答1:
You should try using ${HOME} rather than ~
as tilde expansion is not reliable in a cron job.
See this as an example. Here is more information about tilde expansion.
来源:https://stackoverflow.com/questions/50296898/can-i-use-a-tilde-in-a-mysqldump-cronjob-linux-cron-is-not-running