"echo" prints the options in crontab

0

I'm running Rasbian 3.12.26+ on a Pi model B.

Here is what my cron entry looks like:

* * * * * sleep 11; { echo -en "\e[1;4;33m"; date; echo -en "\e[0m"; curl -k "http://sampleurl.com/update.php"; } >> /var/log/cron/calls.log

Here is what my log looks like:

-en \e[1;4;33m
Thu Sep  4 14:29:13 UTC 2014
-en \e[0m
This is output from curl!

However, when I just paste the command into bash, it works as intended:

{ echo -en "\e[1;4;33m"; date; echo -en "\e[0m"; curl -k "http://sampleurl.com/update.php"; } >> /var/log/cron/calls.log

And the output is

Thu Sep  4 14:27:51 UTC 2014
This is output from curl!

With the first line underlined, bold and yellow as intended.

For some reason, when run by a crontab, the echo prints the "-en" instead of taking it as an argument. As a result, the color escape sequences do not get escaped.

What gives?

Nikita240

Posted 2014-09-04T14:42:02.650

Reputation: 117

Answers

2

It is probably that cron uses /bin/sh. See for yourself by comparing the output of the following:

/bin/sh -c '{ echo -en "\e[1;4;33m"; date; echo -en "\e[0m"; curl -k "http://sampleurl.com/update.php" ; } > /tmp/1'

The above produces the output you are getting

/bin/bash -c '{ echo -en "\e[1;4;33m"; date; echo -en "\e[0m"; curl -k "http://sampleurl.com/update.php" ; } > /tmp/1'

Whereas the same command under bash produces the output you want

Alex Zeffertt

Posted 2014-09-04T14:42:02.650

Reputation: 186

How can I change which shell crontab executes? – Nikita240 – 2014-09-04T14:50:36.213

add SHELL=/bin/bash on top of your cron – johnshen64 – 2014-09-04T14:53:08.463

Another way to get your escape sequences to produce color is to change echo (which the shell treats as a built-in command) to /bin/echo (which is a separate program). (If that doesn't work, try /usr/bin/echo.) – G-Man Says 'Reinstate Monica' – 2014-09-04T15:05:43.343