31

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.

fedorqui
  • 275,237
  • 103
  • 548
  • 598
user3647822
  • 331
  • 3
  • 5
  • Have you tried escaping `%`? `curl -w "\%{time_total}\n"` ...` – fedorqui Nov 25 '14 at 09:48
  • possible duplicate of [Cron error with using backquotes](http://stackoverflow.com/questions/3444595/cron-error-with-using-backquotes) – tripleee Nov 25 '14 at 11:07
  • For general `cron` troubleshooting, please review https://stackoverflow.com/questions/22743548/cronjob-not-running – tripleee Jan 19 '23 at 08:13

1 Answers1

53

% 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
         ^
r3mainer
  • 23,981
  • 3
  • 51
  • 88
fedorqui
  • 275,237
  • 103
  • 548
  • 598