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.

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:

#!/bin/bash

OUTPUT=""
TEMPFILE=/tmp/dsr.output
MAILTO="yourmom@yourmomshouse.com"
INSTALL_DIR=/usr/local/clearleap/scripts/daily-storage-report

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" > $TEMPFILE
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/dsr.sh 

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
3  
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 - codeproject.com/Articles/15956/… –  Zoredache Jan 30 '13 at 19:34

1 Answer 1

I think your problem lies here:

echo "$OUTPUT" > $TEMPFILE

It should be

echo "$OUTPUT" >| $TEMPFILE

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

share|improve this answer

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.