check whether the value changes or not!

HI all,

I need help in writing a shell script for the following logic

I have a file abc.txt and it contains a number x. The number in the file abc.txt changes every day. I need to develop a shell script which on every run checks the number in the file and increments a variable by 1 if a new number is found( if the number doesnt change the variable will not increment by 1).

Can any one help me out in this. Thanks!

How often do you want to run the check? You could either use a corntab script and a temp file or leave a script running a looping the check....

Thanks for the response! The script is run manually by me only to check for the changed value

I ain't sure what you really want, but try this:

NUMBER=`cat abc.txt`

if [ ! -f ~/tmp.file ]; then
    touch ~/tmp.file
    echo "$NUMBER:1" >> ~/tmp.file
    echo "First number saved, variable set to 1"
    exit
else
    OLDNUMBER=`cat ~/tmp.file | awk -F":" '{print $1}'`
    VARIABLE=`cat ~/tmp.file | awk -F":" '{print $2}'`
    if [ "$OLDNUMBER" != "$NUMBER" ]; then
        VARIABLE2=$(( $VARIABLE + 1 ))
        cat /dev/null > ~/tmp.file
        echo "$NUMBER:$VARIABLE2" >> ~/tmp.file
        echo "New variable: $VARIABLE2"
    else
        echo "Number hasn't changed, variable stays $VARIABLE"
    fi
fi

Tech one! Thanks a million, that is what i needed!

Once again Thanks a lot!