用于发送警报的脚本

时间:2018-01-23 17:17:08

标签: bash

请注意,我有以下bash脚本,我试图采用一种方式,当$GET_SEGMENT_MATCH / $GET_TOTAL_SESSIONS$GET_BOUNCES / $GET_TOTAL_SESSIONS$GET_PAGEVIEW_CHANAGES / $GET_AVG_VIEWS_FOR_WEEK阈值低于50%时,脚本会向我发送通知。请,建议谢谢。

#!/usr/bin/env bash
#!/bin/bash

if [ -z "$1" ]; then
        echo "USAGE: test_mailable.sh [code] [max_session_date]"
        exit 0
fi
CLIENT_CODE="$1"
MAX_DATE="$2"

#client_id=$1

GET_SEGMENT_MATCH=$(echo "SELECT SUM(segment_match) as value_today FROM tag_$CLIENT_CODE.daily_traffic where session_date_cst ='$MAX_DATE';" | mysql --login-path=local --skip-column-names)

GET_TOTAL_SESSIONS=$(echo "SELECT SUM(sessions) as value_today FROM tag_$CLIENT_CODE.daily_traffic where session_date_cst ='$MAX_DATE';" | mysql --login-path=local --skip-column-names)

GET_MAILABLE_RATE=$(echo "SELECT SUM(mailable) as value_today FROM tag_$CLIENT_CODE.daily_traffic where session_date_cst ='$MAX_DATE';" | mysql --login-path=local --skip-column-names)

GET_BOUNCES=$(echo "select sum(bounces) from tag_$CLIENT_CODE.daily_traffic where session_date_cst='$MAX_DATE';" | mysql --login-path=local --skip-column-names)

GET_PAGEVIEW_CHANAGES=$(echo "SELECT SUM(views) as value_today from tag_$CLIENT_CODE.daily_traffic where session_date_cst ='$MAX_DATE';" | mysql --login-path=local --skip-column-names)

#GET_VIEWS_FOR_WEEK=$(echo "AVG(views)  as value_today from  tag_$CLIENT_CODE.daily_traffic where session_date_cst =$MAX_DATE - INTERVAL 7 DAY;" | mysql --login=path=local --skip-column-names)

GET_AVG_VIEWS_FOR_WEEK=$(echo "SELECT ROUND(SUM(views)/7) as value_today from tag_$CLIENT_CODE.daily_traffic where session_date_cst between DATE_SUB('$MAX_DATE', INTERVAL 7 DAY) and '$MAX_DATE';" | mysql --login-path=local --skip-column-names)


echo "Total sessions: $GET_TOTAL_SESSIONS"

echo "Segment match: $GET_SEGMENT_MATCH"

echo "Mailable: $GET_MAILABLE_RATE"

echo "Bounces: $GET_BOUNCES"

echo "PageView: $GET_PAGEVIEW_CHANAGES"

echo "Average views for 7 days: $GET_AVG_VIEWS_FOR_WEEK"

GET_NEUSTAR_SEGMENT_CODE_PERCENT=$(echo "scale=2; $GET_SEGMENT_MATCH / $GET_TOTAL_SESSIONS" | bc -l)  

echo "GET_NEUSTAR_SEGMENT_CODE_PERCENT: $GET_NEUSTAR_SEGMENT_CODE_PERCENT" 

GET_MAILABLE_RATE_PERCENT=$(echo "scale=2; $GET_MAILABLE_RATE / $GET_TOTAL_SESSIONS" | bc -l)

echo "GET_MAILABLE_RATE_PERCENT:$GET_MAILABLE_RATE_PERCENT"

GET_BOUNCES_RATE_PERCENT=$(echo "scale=2; $GET_BOUNCES / $GET_TOTAL_SESSIONS" | bc -l)

echo "GET_BOUNCES_RATE_PERCENT: $GET_BOUNCES_RATE_PERCENT"

GET_PAGEVIEW_CHANAGES_PERCENT=$(echo "scale=2; $GET_PAGEVIEW_CHANAGES / $GET_AVG_VIEWS_FOR_WEEK" | bc -l)

echo "GET_PAGEVIEW_CHANAGES_PERCENT: $GET_PAGEVIEW_CHANAGES_PERCENT"

0 个答案:

没有答案