百分号%在crontab中不起作用 [英] Percent sign % not working in crontab
问题描述
我有一个cron问题与 curl
:
curl - w%{time_total} \\\
-o / dev / null -s http://myurl.com>> 〜/ log
工作得很好,并在日志文件中添加一行,其中包含total_time。
$ b这不是一个路径问题,因为 curl http ://myurl.com>> 〜/ log
。
%
是 crontab
的特殊字符。从 man 5 crontab
:
行)指定要
$ c> character:
运行的命令。直到换行符或
%字符的行的整个命令部分将由/ bin / sh或由cronfile的SHELL变量中指定的
的shell执行。
命令中的%字符,除非使用反斜杠()转义,将被更改为
换行字符,第一个%之后的所有数据将发送到
curl -w%{time_total} \\\
-o / dev / null -s http ://myurl.com>> 〜/ log
到
curl -w\%{time_total} \\\
-o / dev / null -s http://myurl.com>> 〜/ log
^
I have a cron issue with
curl
:curl -w "%{time_total}\n" -o /dev/null -s http://myurl.com >> ~/log
works great and add a line in log file with total_time.
But the same line with cron doesn't do anything.
It's not a path problem because
curl http://myurl.com >> ~/log
works.解决方案
%
is a special character forcrontab
. Fromman 5 crontab
:The "sixth" field (the rest of the line) specifies the command to be run. 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 characters, and all data after the first % will be sent to the command as standard input.
So you need to escape the
%
character:curl -w "%{time_total}\n" -o /dev/null -s http://myurl.com >> ~/log
to
curl -w "\%{time_total}\n" -o /dev/null -s http://myurl.com >> ~/log ^
这篇关于百分号%在crontab中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!