#!/bin/bash
#fmt as $1:date $2:command $3....
echo [`date`] exec $0 >> /var/log/crond.log

wake_up_now() {
    echo "aabbccddee" > /etc/base/.sync
    sync
    rm -f /etc/base/.sync
}

standby=0
config_file=/tmp/TOS_CONFIG/standby.conf

if [ -e $config_file ]; then
    buffer=`awk -F= '/standby/ {print $2}' $config_file`
    [ ! -z "$buffer" ] && standby=$buffer
fi

if [ "$standby" = "0" ]; then
    locker=/var/lock/standby.lock
    if [ ! -e $locker ]; then
        touch $locker
    else
        mtime=`stat -c "%Z" $locker`
        now=`date +%s`
        let diff=$now-$mtime
        # wake up after 10 mins ...
        if [ $diff -le 600 ]; then
            exit 1
        fi
        touch $locker
        wake_up_now
    fi
fi

exit 0
