bash - 百分号 % 在 crontab 中不起作用

标签 bash curl cron

我有一个关于 curl 的 cron 问题:

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

效果很好,在日志文件中添加一行 total_time。

但是与 cron 相同的一行没有做任何事情。

这不是路径问题,因为 curl http://myurl.com >> ~/log 有效。

最佳答案

%crontab 的特殊字符。来自 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.

所以你需要转义%字符:

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

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

关于bash - 百分号 % 在 crontab 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27123367/

相关文章:

javascript - 如何使用shell在gulp中读取?

php - 如何避免来自 LinkedIn 的 "HTTP/1.1 999 Request denied"响应?

json - 获取 HTTP 状态 400 - 客户端发送的请求在语法上不正确 : using curl to post/put json request

linux - acquia服务器上的shell脚本调度

django - 在 aws elastic beanstalk 上运行 cron 作业 - django

python - 如何修复 'in bash after checking with if condition else statements also getting executed'?

bash - 如何使用 sudo 运行两个命令?

linux - 如何将文件列表提供给 bash 脚本

http - 在 HTTP 中,仅提供路径作为 Request-URI 时是否允许查询?

php - Cron 作业在早上 5 点到晚上 10 点之间每 90 秒运行一次 PHP 脚本?