0

Possible Duplicate:
What’s wrong with these two cron job’s?

I want to print a formatted output from a file containing lines of date, time, long number, and long number. I set LC_NUMERIC to UTF and use the %'d flag characters to produce numeric grouping of thousands.

The following line in crontab produces an error of

/bin/sh: -c: line 0: unexpected EOF while looking for  matching `"'

when the cronjob runs.

@daily LC_NUMERIC=en_US.UTF-8 /usr/bin/printf "%s %s %'d %'d\n" \
          $(/usr/bin/tail -n 31 /var/log/bandwidth)

Newline added for readability

The identical line (without @daily) in a script works fine.

I would guess that cron is choking on the %'d part and can't find the closing ". Why?

2 Answers2

1

I would suggest you to put LC_NUMERIC=en_US.UTF-8 /usr/bin/printf "%s %s %'d %'d\n" $(/usr/bin/tail -n 31 /var/log/bandwidth) in a file and chmod it to 770 and put that file name there in the crontab.

0

To set environment variables in a crontab file, you need to put them on their own line. The setting will affect all cron commands after that line.

LC_NUMERIC=en_US.UTF-8
@daily /usr/bin/printf "%s %s %'d %'d\n" $(/usr/bin/tail -n 31 /var/log/bandwidth)

But without knowing what's in /var/log/bandwidth it's impossible to say what's the real problem there.

angus
  • 12,321
  • 3
  • 45
  • 40
  • 1
    You don't know what cron implementation the questioner is using. Usually it's Vixie cron, but different distributions have different defaults. Setting environment variables in this way doesn't work for all cron implementations; sometimes by design. See my comment to this answer: http://unix.stackexchange.com/a/52332/4801 – dubiousjim Oct 20 '12 at 12:09
  • @angus Thanks re the environment variables. That helped.

    The full answer is to escape the %, as per man 5 crontab.

    – Nick Coleman Oct 24 '12 at 01:41
  • @dubiousjim In this case it is Vixie cron on some VPSs, but at home I use Dillon's cron on Slackware. I think I know who you are . Thanks for your work. I much prefer your crond with FREQ, etc. – Nick Coleman Oct 24 '12 at 01:45