crontab中的%需转义
2017-09-17 18:25
417 查看
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.
示例:
$ 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
对%需要使用\进行转义,否则不能按预期执行,正确做法为:
* * * * * 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.
示例:
$ 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
相关文章推荐
- linux定时任务crontab的使用,curl命令中url避免使用&,或对&进行转义
- crontab中命令行中的百分号(%)需要做转义
- oracle & 和 ' 特殊字符处理 ( like 'GAC/&_%' escape '&'; 这里面的 / 居然将& 转义了 为什么?)
- 各种各样转义符号的对照表、转换方法
- WebService传递XML字符串转义问题
- C/C++中的转义字符
- crontab 详解
- Android studio关于含有转义字符的字符串无法Log,以及如何去掉转义字符问题
- 关于 JSTL c:out 对 XML html 自动转义 转义的禁用
- Linux 中的定时器 crontab
- Linux的主动实验措施cron和crontab(2)
- 在MVC控制器里面使用dynamic和ExpandoObject,实现数据转义的输出
- Linux——Crontab
- linux定时任务之crontab命令
- 转余晟老师的正则专栏文章:(一):纠结的转义
- java 防SQL注入 html编码入侵 特殊字符转义 方法入参检测工具 (Spring)
- PHP中输出转义JavaScript代码的实现代码
- Linux的cron和crontab
- 关于数据库中的%、_和?转义
- linux下的crontab服务