使用反引号的 Cron 错误 [英] Cron error with using backquotes

查看:23
本文介绍了使用反引号的 Cron 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下从命令行工作正常

/usr/bin/mysqldump -uUser -pPass Db_name > /var/www/db_backup/db.`date +%Y%m%d%H%M`.sql 

但是当我尝试在 cron 中执行此操作时,出现错误:

but when I try to do that in cron, I get the error:

bad ` sign 
errors in crontab file, can't install

我看到网上的其他人通过转义百分号解决了同样的问题,但这没有帮助,我在没有格式说明符的反引号中使用日期进行了尝试,但仍然出现错误.

I saw someone else on the net solve the same problem by escaping the percent signs, but that didn't help and I tried it with just date inside backquotes with no format specifiers and still got the errors.

我还看到了用单引号或双引号括起来的日期参数,但这也无济于事.

I've also seen date's argument enclosed in single or double quotes, but that doesn't help either.

当然,我可以把它放到一个脚本中并执行我想的——但这有什么乐趣?

Granted I could just throw it into a script and execute that I suppose - but what fun is that?

有什么想法吗?我使用的是 RHEL 5.

Any ideas? I'm using RHEL 5.

推荐答案

尝试使用 $() 而不是反引号.而且您可能确实需要转义百分号,因为 cron 否则会将它们转换为换行符.

Try it with $() instead of backticks. And you probably do need to escape the percent signs since cron converts them to newlines otherwise.

* 0 * * * /usr/bin/mysqldump -uUser -pPass Db_name > /var/www/db_backup/db.$(date +\%Y\%m\%d\%H\%M).sql

此外,您应该将密码存储在选项中文件具有安全权限(例如 600 或 640),而不是在命令行上传递它.

Also, you should store the password in an option file with secure permissions (eg. 600 or 640) instead of passing it on the command line.

这篇关于使用反引号的 Cron 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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