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

查看:124
本文介绍了使用反引号的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.

我也看过

授予我可以把它放到一个脚本并执行,我想 - 但有什么乐趣是吗?

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天全站免登陆