计算变化率的脚本

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                       



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值