1.date -d "1 weeks/days ago" +"%Y-%m-%d"
2. echo "$a $b"|awk '{c = ($1 - $2)/$2;}END{print c;}'
3. echo "2013-01-16"|grep "[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}"
#!/bin/bash
MONITOR_PATH="/home/a/share/monitor/data"
function usemessage
{
echo -e "./get_ecpm_cost.sh ---> revenue change percent"
echo -e "./get_ecpm_cost.sh %Y%m%d ---> get this day revenue"
}
WEEKDAY=`date +%u`
TODAY=`date +"%Y%m%d"`
YESTODAY=`date -d "1 days ago" +"%Y%m%d"`
LASTWEEK=`date -d "1 week ago" +"%Y%m%d"`
TODAY_PVCOSTFILE=$MONITOR_PATH/pvcost_sum_halfhourly.$TODAY
YESTODAY_PVCOSTFILE=$MONITOR_PATH/pvcost_sum_halfhourly.$YESTODAY
LASTWEEK_PVCOSTFILE=$MONITOR_PATH/pvcost_sum_halfhourly.$LASTWEEK
HALFHOUR_SETTLE_NUM=`cat $TODAY_PVCOSTFILE|wc -l`
SETTLE_DATA_HOUR=`tail -1 $TODAY_PVCOSTFILE|awk '{print $1}'`
TODAY_SUM=`cat $TODAY_PVCOSTFILE|awk '{total += $5;}END{print total;}'`
YESTODAY_SUM=`head -$HALFHOUR_SETTLE_NUM $YESTODAY_PVCOSTFILE|awk '{total += $5;}END{print total;}'`
LASTWEEK_SUM=`head -$HALFHOUR_SETTLE_NUM $LASTWEEK_PVCOSTFILE|awk '{total += $5;}END{print total;}'`
if [ $# -eq 0 ];then
echo -e "today has produced settle data now:\n$SETTLE_DATA_HOUR"
today_sum_wan=`echo $TODAY_SUM|awk '{res = $1 / 1000000000;}END{print res;}'`
echo -e "today settle data now:\n$today_sum_wan"
# cal data
if [ $WEEKDAY == "1" -o $WEEKDAY == "6" -o $WEEKDAY == "7" ];then
settle_percent=`echo "$TODAY_SUM $LASTWEEK_SUM"|awk '{change_percent = ($1 - $2)/$2;}END{print change_percent;}'`
lastweek_sum_wan=`echo $LASTWEEK_SUM|awk '{res = $1 / 1000000000;}END{print res;}'`
echo -e "lastweek settle data now:\n$lastweek_sum_wan"
else
settle_percent=`echo "$TODAY_SUM $YESTODAY_SUM"|awk '{change_percent = ($1 - $2)/$2;}END{print change_percent;}'`
yestoday_sum_wan=`echo $YESTODAY_SUM|awk '{res = $1 / 1000000000;}END{print res;}'`
echo -e "yestoday settle data now:\n$yestoday_sum_wan"
fi
echo -e "settle_percent=$settle_percent"
elif [ $# -eq 1 ];then
echo "$1"|grep "[0-9]\{4\}[0-9]\{2\}[0-9]\{2\}" > /dev/null
if [ $? -eq 0 ];then
date_edsp_sum=`cat $MONITOR_PATH/pvcost_sum_halfhourly.$1|awk '{total += $3;}END{print total;}'`
date_ecpm_sum=`cat $MONITOR_PATH/pvcost_sum_halfhourly.$1|awk '{total += $5;}END{print total;}'`
date_edsp_sum_wan=`echo $date_edsp_sum|awk '{res = $1 / 1000000000;}END{print res;}'`
date_ecpm_sum_wan=`echo $date_ecpm_sum|awk '{res = $1 / 1000000000;}END{print res;}'`
date_sum_wan=`echo $date_edsp_sum_wan $date_ecpm_sum_wan|awk '{sum = $1 + $2}END{print sum}'`
echo -e "$1 settle revenue is:"
echo "$date_edsp_sum_wan $date_ecpm_sum_wan $date_sum_wan"|awk 'BEGIN{OFS="\t";print "edsp\tecpm\tsum"}{print $1,$2,$3}'
else
usemessage
fi
else
usemessage
fi