#!/bin/sh
#restart after 1 hour
a="`/opt/bin/at -f /opt/bin/sms now + 1 hour 2> /dev/null`"
if [ -f /tmp/smsboot1 ]; then
#try to set date
#get info
o="`/opt/bin/open2300`"
#o="jhkjh"
if [ "`echo $o | /opt/bin/grep -c "Osa"`" = "1" ]; then
#successfully get info from ws2300
echo $o > /tmp/smsdate
#at last set date
date `cut -c1-12 < /tmp/smsdate`
#because of new (in future!) time set
rm /opt/var/spool/cron/atjobs/*
a="`/opt/bin/at -f /opt/bin/sms now + 1 minute 2> /dev/null`"
rm /tmp/smsboot1
else
echo "notset"
fi
else
#date set already
#check if time more than 21 00
if [ `date +%H%M` -ge 2100 ]; then
#check if we should send sms
if [ -f /opt/smsdate ]; then
date +%m%d%H%M%Y > /tmp/smsdate
#year
if [ "`cut -b9-12 < /opt/smsdate`" = "`cut -b9-12 < /tmp/smsdate`" ]; then
#month
if [ "`cut -c1-2 < /opt/smsdate`" = "`cut -c1-2 < /tmp/smsdate`" ]; then
#day
if [ "`cut -c3-4 < /opt/smsdate`" = "`cut -c3-4 < /tmp/smsdate`" ]; then
#no need to send sms
exit 0
fi
fi
fi
fi
#send sms
o="`/opt/bin/open2300`"
if [ "`echo $o | /opt/bin/grep -c "Osa"`" = "1" ]; then
#successfully get info from ws2300
echo $o > /tmp/smsdate
/opt/bin/smssend
fi
fi
fi