> ~/log ...">

Percent sign% does not work in crontab

I have a cron problem with curl :

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

works fine and adds a line to the log file with total_time.

But the same line with cron does nothing.

This is not a path issue because curl http://myurl.com >> ~/log works.

+5
source share
1 answer

% is a special character for crontab . From man 5 crontab :

The sixth field (the rest of the line) indicates the command to be run. The entire part of the line command, up to a new line or the "%" character, will be executed using / bin / sh or the specified shell in the SHELL cronfile variable. The character "%" in the command, if it is not reset using the backslash (\), will be changed to newline characters and all the data after the first% command is sent 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 ^ 
+7
source

Source: https://habr.com/ru/post/1207654/


All Articles