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