Can I use a tilde ( ~ ) in a mysqldump cronjob? Linux Cron is not running

為{幸葍}努か 提交于 2021-02-17 07:12:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!