2

I'm using a script for testing broadband speed and I would like to set up a cronjob for testing every n minutes and output to a file. The command to launch it from a shell console and append to logfile prepending a line with the current date is

tespeed.py -w | sed -e "s/^/$(date +\"%d-%m-%y\ %T\"), /" >>tespeedlog.csv

But if I use this command in a cronjob something doesn't work; the syslog reports:

Sep 25 13:23:01 raspberrypi /USR/SBIN/CRON[6719]: (pi) CMD (/home/pi/tespeed/tespeed.py -w | sed -e "s/^/$(date +')

What shoud I check?

2

1 Answer 1

4

Create a wrapper script as there may be a problem with escaping date format. The problem seems to be with % character which may be interpreted as a new line specifier in some cron schedulers:

Put this to the file /usr/local/bin/wrpr.sh:

#!/bin/sh
tespeed.py -w | sed -e "s/^/$(date +\"%d-%m-%y\ %T\"), /" >> /tmp/tespeedlog.csv

Make it executable:

chmod u+x /usr/local/bin/wrpr.sh

And schedule it with cron (this will override the current user's crontab):

echo "* * * * * /usr/local/bin/wrpr.sh" | crontab

Otherwise, use crontab -e to add it to the current user's crontab.

1
  • @alzambo if it works, please accept this answer, that's the way to say thanks on the stack exchange sites.
    – terdon
    Sep 25, 2013 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.