日期 +“%Y-%m-%d"在 crontab 中 [英] date +"%Y-%m-%d" in crontab
本文介绍了日期 +“%Y-%m-%d"在 crontab 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在 crontab -e
中输入以下内容:
If I put the following in crontab -e
:
* * * * * date +"%Y-%m-%d" > /home/apps/temp/env.txt
没有创建env.txt
.
如果我将上面的行更改为:
If I change the above line to:
* * * * * date > /home/apps/temp/env.txt
env.txt
已正确创建.
如何在 cron 中格式化 date
?
How can I format date
in cron?
推荐答案
你需要对每一个%
进行转义:
You need to escape each one of the %
:
* * * * * date +"\%Y-\%m-\%d" > /home/apps/temp/env.txt
或者更好的是,删除引号并像这样离开:
Or even better, remove the quotes and leave like this:
* * * * * date +\%Y-\%m-\%d > /home/apps/temp/env.txt
这篇关于日期 +“%Y-%m-%d"在 crontab 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文