Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
my crontrab entry looks like this: '22 9 * * * /data/home/cwolff/scripts/archive_access_logs.sh' –  rontron Feb 3 '12 at 8:55
add comment

2 Answers

up vote 3 down vote accepted

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.

share|improve this answer
    
thanks a lot - setting the LANG env in crontab solved this issue! –  rontron Feb 3 '12 at 12:05
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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