Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question is related to Gentoo Linux.

I have cron job that runs every morning at 10AM. The cron job calls a bash script which in turn calls a groovy script that queries the database for a column of data and emails the result to a recipient list.

Every day the script executes, it sends out the exact same data. When I run the script manually it, reports (and emails) the correct data. I'm at a complete loss of how to further troubleshoot this. What gives?

Here's my cronjob script:



export CLASSPATH=$CLASSPATH:$INSTALL_DIR/lib/postgresql-8.3-603.jdbc4.jar:$INSTALL_DIR

OUTPUT=$(/opt/groovy/bin/groovy $INSTALL_DIR/DailyStorageReport.groovy)
echo $OUTPUT

echo $OUTPUT | /bin/mailx  -s "Daily Storage Report" $MAILTO

Here is the cronjob itself, which lives in /etc/cron.d/dsr_cron:

0 10 * * * root  /usr/local/clearleap/scripts/daily-storage-report/ 

Please let me know if you'd like to see the code from the groovy script. I have no idea why it appears to be caching!

Any help is greatly appreciated!

share|improve this question
appart from the email, is the $OUTPUT correct ? Have you checked the content of the TEMPFILE with and without the cronjob ? – Rosco Jan 30 '13 at 16:42
Does the account you're running it under have access to modify /tmp/dsr.output? – ceejayoz Jan 30 '13 at 17:00
The $TEMPFILE contains the incorrect data, the email that gets sent has the incorrect data. BUT, when i run the script manually it spits out (and emails) the correct data! – slappyjam Jan 30 '13 at 17:02
what do you get when you run echo $CLASSPATH from the command line? It is possible that the environment variables cron has could be different from what is available when you run it manually. – Daniel t. Jan 30 '13 at 17:07
TEMPFILE=/tmp/dsr.output - I strongly suggest you consider using mktemp or something that will create a randomly name temporary file. Imagine what would happen if /tmp/dsr.output didn't exist and some unprivileged user or serves made /tmp/dsr.output a symlink to /etc/passwd? Secure temp file usage -… – Zoredache Jan 30 '13 at 19:34

I think your problem lies here:


It should be


Since > if the file exists won't overwrite it unless noclobber is set.

share|improve this answer

Your problem seems to be that your Groovy doesn't run from cron at all, so it just keep sending the same email.

What you can do, add to top of your script:

source /etc/bashrc

The full line could look like this:

30 * * * * source /etc/bashrc; /opt/groovy/bin/groovy /path/to/groovy/script.groovy >>/var/log/MyGroovyScript-stdout.log 2>/var/log/MyGroovyScript-error.log

Or whatever is appropriate for your environment.

In that file, /etc/bashrc, you need to add the following:

export JAVA_HOME=/usr/java/latest

Once you have JAVA_HOME in your environment variables it will work. Cron does not use /etc/bashrc on it's own so that your JAVA variable might be missing completely.

share|improve this answer

Your Answer


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.