我可以在mysqldump cronjob中使用波浪号(〜)吗?Linux Cron没有运行 [英] Can I use a tilde ( ~ ) in a mysqldump cronjob? Linux Cron is not running

查看:65
本文介绍了我可以在mysqldump cronjob中使用波浪号(〜)吗?Linux Cron没有运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题与 此人 此人,我的命令在本地工作,但在Cron任务,什么也没发生.

这是我要运行的内容:

 /usr/bin/mysqldump -u root -ppassword database_name>〜/Documents/dump.sql 

当我直接输入我的终端时,这在本地有效!它可能会抛出一个错误:

  mysqldump:[警告]在命令行界面上使用密码可能不安全 

但是它仍然有效.如果我在命令前输入用户 root ,它甚至可以工作.

现在,这里是CRON(只是尝试每分钟运行一次以测试它是否有效)

  */1 * * * * root/usr/bin/mysqldump -u root -ppassword数据库名称>〜/Documents/dump.sql 

然后...什么都没发生.我从 这个问题 和[this人]是语法问题.我不知道为什么这个CRON无法运行!

解决方案

您应该尝试使用$ {HOME}而不是,因为波浪符号扩展在cron作业中不可靠.

请参见作为示例.此处是有关波浪号扩展的更多信息.>

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!

解决方案

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.

这篇关于我可以在mysqldump cronjob中使用波浪号(〜)吗?Linux Cron没有运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆