前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >crontab条目包含%号问题

crontab条目包含%号问题

作者头像
一见
发布2019-03-14 15:22:46
5030
发布2019-03-14 15:22:46
举报
文章被收录于专栏:蓝天蓝天

crontab条目中包含%号,最常见的取时间,如:date +%d, 对%需要使用\进行转义,否则不能按预期执行,正确做法为: * * * * * echo "`date +\%d`" > /tmp/r1r.txt 而不能为 * * * * * echo "`date +%d`" > /tmp/r1r.txt %是crontab的特殊字符,所有%后的被当作了标准输入,这可以通过“ man 5 crontab”查看到说明: The entire command portion of the line, up to a newline or a "%" character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the cronfile. A "%" character in the command, unless escaped with a backslash (\),  will be changed into newline char-acters, and all data after the first % will be sent to the command as standard input. 示例:

代码语言:javascript
复制
 $ cat /tmp/hello.txt 
 cat: /tmp/hello.txt: 没有那个文件或目录
 $ echo -e "`crontab -l`\n* * * * * cat > /tmp/hello.txt % hello word"|crontab -
 $ crontab -l|grep hello.txt
 * * * * * cat > /tmp/hello.txt % hello word
 $ cat /tmp/hello.txt 
  hello word
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-08-28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档