2

I have a simple bash script wich works fine when running in command line, but not in crontab:

#!/bin/bash
PATH=/usr/bin:/bin

for f in /data/home/cwolff/tmp/*access_log*.txt;
do
egrep "r:[A-Z]+ \S+[^\.\s]{5} " $f >> $f.min
done

When running in crontab it outputs empty *.min files. I read about some character like % need to be escaped in crontab, but I'm not using any of them.

1
  • my crontrab entry looks like this: '22 9 * * * /data/home/cwolff/scripts/archive_access_logs.sh'
    – rontron
    Feb 3, 2012 at 8:55

2 Answers 2

3

Be careful with ranges like [A-Z], as the meaning of that depends on the locale. It might be [ABC...], but it might also be [AaBbCc...]. [:upper:] is well-defined.

So, my best bet would be to check the environment in your login shell vs cron, especially LC_ALL, LC_COLLATE, LC_CTYPE, LANG.

1
  • thanks a lot - setting the LANG env in crontab solved this issue!
    – rontron
    Feb 3, 2012 at 12:05
1

This could be caused by permissions.

You would see exactly this behaviour if you have permission to read all the files in /data/home/cwolff/tmp/*access_log*.txt but the user whose crontab you are running this from doesn't.

This will also be the case if /data is mounted using NFS without the no_root_squash option and the crontab is root's.

Errors from cron jobs are usually mailed to the user in question. If you haven't spent any time configuring your mail setup, these are probably in /var/spool/mail/user.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .