Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

marked as duplicate by Gilles, jasonwryan, Renan, warl0ck, Mat Oct 21 '12 at 13:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
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: 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 1: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 <g>. Thanks for your work. I much prefer your crond with FREQ, etc. –  Nick Coleman Oct 24 '12 at 1:45
add comment

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