вторник, 25 августа 2009 г.

FreeBSD billing: переключение скоростей

#!/usr/local/bin/bash

DATE4LOG=`date '+%Y/%m/%d %H:%M:%S'`
LOGFILE=/var/log/switchdaynight.log
# ( name dayspeed nightspeed ... )
TARIFS=( unlim 163000 320000 unlim2 307000 600000 \
unlim3 665000 1300000 unlim4 1270000 2000000 )
CNT1=${#TARIFS[@]}
QOSTARIFS=( korp 256000 128000 korp2 512000 128000 \
korp3 1024000 128000 korp4 1500000 128000 )
CNT2=${#QOSTARIFS[@]}

DATE=`date '+%H'`
#day2000
DAY=1
QOSDAY=2
if [ $DATE -lt 8 ]; then
#night
DAY=2
#echo "DAY=2"
elif [ $DATE -lt 20 ]; then
#day
QOSDAY=1
#echo "QOSDAY=1"
fi

function sql {
TARIF=$1
RATE=$2
let BURST=$RATE/5
INSHAPE="update radgroupreply set value='in#2#Inet=all rate-limit \
  $RATE $BURST' where groupname='$TARIF' and left(value,4)='in#2';"
OUTSHAPE="update radgroupreply set value='out#2#Inet=all rate-limit \
  $RATE $BURST' where groupname='$TARIF' and left(value,5)='out#2';"
echo $INSHAPE
echo $OUTSHAPE
}
(
for (( i=0;i<$CNT1;i++, i++, i++)); do
    j=i+$DAY
    sql ${TARIFS[${i}]} ${TARIFS[${j}]}
done
for (( i=0;i<$CNT2;i++, i++, i++)); do
    j=i+$QOSDAY
    sql ${QOSTARIFS[${i}]} ${QOSTARIFS[${j}]}
done
) | /usr/local/bin/mysql -u xxx --password=xxx radius

echo "$DATE4LOG: switchdaynight.sh done" >> $LOGFILE

Комментариев нет: