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 the following script to update file based on MD5 comparison, script works perfectly from command line but when i put it in cron nothing happens. I only have root user on the system, script is owned by root, in crontab am calling the script like this: /bin/bash /home/papa/systems/sron.sh

Here is my script, I have tried all the solutions I have read till now but no progress, please help.

#!/bin/bash


PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

MD5FILE=/tmp/.md5oldjar
MD5FILENEW=/tmp/.md5newjar
FILE_TO_CHECK=/tmp/rose.jar
URL=http://xxxx
DESTINATION=/tmp

rm -rf $FILE_TO_CHECK

wget $URL -P $DESTINATION


#echo generating MD5 for $FILE_TO_CHECK  

echo `md5sum $FILE_TO_CHECK` > $MD5FILENEW
MD5PRINT=`cat $MD5FILENEW`

if [ -z "$MD5PRINT" ]; then
    echo "ERROR Recived an empty MD5PRINT thats not valid, aborting"
    exit 1


fi

OLDMD5PRINT=`cat $MD5FILE`



if [ -z "$OLDMD5PRINT" ]; then
    echo "Got an empty string from the oldfile, aborting"
    echo $OLDMD5PRINT 
    exit 1
fi


if [ "$OLDMD5PRINT" != "$MD5PRINT" ]; then 
    echo "File has changed"
    echo "updating MD5 file...."
    echo $MD5PRINT > $MD5FILE
    echo "file content:"
    cat $MD5FILE
    echo `date` >> /home/log
    echo done
else
    echo nothing >> /home/log
fi
share|improve this question
    
what does your crontab look like? –  Zypher Oct 31 '11 at 22:00
    
*/1 * * * * /bin/bash /home/papa/systems/sron.sh –  APZ Oct 31 '11 at 22:01
    
Can you run /bin/bash /home/papa/systems/sron.sh in the shell? –  mr-euro Oct 31 '11 at 22:02
    
yes it works perfectly from comand line –  APZ Oct 31 '11 at 22:02
2  
Try adding MAILTO=root at the top of the crontab and see if you get any error messages –  Zypher Oct 31 '11 at 22:03

2 Answers 2

Try adding >/home/papa/systems/sron.log 2>&1 to the end of line in crontab and watch log to understand what is happening. The most probable reason is that script is not run at all, for example because of error pointed in lain's answer

share|improve this answer

This works fine on a CentOS system I have to hand from a user crontab (crontab -e). Did you put this in root's crontab or did you put it in /etc/crontab (or similar)? If you did then you need to specify your crontab as

*/1 * * * * root /bin/bash /home/papa/systems/sron.sh
share|improve this answer
    
I believe */1 is extraneous; if you just use a star it should run every minute. –  Handyman5 Nov 1 '11 at 17:21
    
@Handyman5: yep, I was using syntax consistent with the OP's - see his comment above. –  Iain Nov 1 '11 at 17:25

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.