Percent sign % not working in crontab

后端 未结 1 689
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 13:07

I have a cron issue with curl:

curl -w \"%{time_total}\\n\" -o /dev/null -s http://myurl.com >> ~/log

works great and ad

相关标签:
1条回答
  • 2020-11-29 13:33

    % is a special character for crontab. From man 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
             ^
    
    0 讨论(0)
提交回复
热议问题