0

I have this command

echo "$(date +"%T") $(sensors | grep -Eo "[0-9]+\.[0-9]+" | head -1)" >> /home/me/temp_log.txt

that gets some sensor data and puts it into a file and I want to run it every half hour. It works fine in the stdin, but when I put it into my crontab file as such:

0,30 * * * * echo "$(date +"%T") $(sensors | grep -Eo "[0-9]+\.[0-9]+" | head -1)" >> /home/me/temp_log.txt

it just doesn't run. Vim is highlighting weird after the % but I'm not sure if that's part of the problem or not.

Dabe
  • 3

1 Answers1

1

Because cron doesn't offer full bash-like parsing. It's easier to:

0,30 * * * * /home/me/bin/mycron

where /home/me/bin/mycron is:

#!/bin/bash
echo "$(date +"%T") $(sensors | grep -Eo "[0-9]+\.[0-9]+" | head -1)" >> /home/me/temp_log.txt

And, since cron has its own idea of PATH, you might need to use a full path for the sensors command.

waltinator
  • 36,399