diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-03-22 23:25:34 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-03-22 23:25:39 +0300 |
commit | 91b6b387e19ad2b2f686e8a27bfc0a027e9eb4d9 (patch) | |
tree | 2be275e79d58e8f8f69166086c11ca3cbe1d9ed3 /e3372-stats.sh | |
parent | c8fb7cd3987d3128bcee5962a5af4cd282add24e (diff) |
eliminate a lot of copypasta by using functions
Diffstat (limited to 'e3372-stats.sh')
-rwxr-xr-x | e3372-stats.sh | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/e3372-stats.sh b/e3372-stats.sh index 1df3f5e..413fe9c 100755 --- a/e3372-stats.sh +++ b/e3372-stats.sh @@ -4,18 +4,14 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" . "$DIR/include.sh" get_token +get_xml "monitoring/traffic-statistics" > $STATUS_FILE -curl -s -X GET "http://$MODEM_IP/api/monitoring/traffic-statistics" \ - -H "Cookie: $COOKIE" \ - -H "__RequestVerificationToken: $TOKEN" \ - -H "Content-Type: text/xml" > modem_status.xml - -CurConnTime=$(cat modem_status.xml | grep CurrentConnectTime | sed -e 's/<[^>]*>//g') -CurrUpload=$(cat modem_status.xml | grep "<CurrentUpload>" | sed -e 's/<[^>]*>//g') -CurrDownload=$(cat modem_status.xml | grep "<CurrentDownload>" | sed -e 's/<[^>]*>//g') -TotalUpload=$(cat modem_status.xml | grep "<TotalUpload>" | sed -e 's/<[^>]*>//g') -TotalDownload=$(cat modem_status.xml | grep "<TotalDownload>" | sed -e 's/<[^>]*>//g') -TotalConnectTime=$(cat modem_status.xml | grep "<TotalConnectTime>" | sed -e 's/<[^>]*>//g') +CurConnTime=$(cat $STATUS_FILE | grep CurrentConnectTime | sed -e 's/<[^>]*>//g') +CurrUpload=$(cat $STATUS_FILE | grep "<CurrentUpload>" | sed -e 's/<[^>]*>//g') +CurrDownload=$(cat $STATUS_FILE | grep "<CurrentDownload>" | sed -e 's/<[^>]*>//g') +TotalUpload=$(cat $STATUS_FILE | grep "<TotalUpload>" | sed -e 's/<[^>]*>//g') +TotalDownload=$(cat $STATUS_FILE | grep "<TotalDownload>" | sed -e 's/<[^>]*>//g') +TotalConnectTime=$(cat $STATUS_FILE | grep "<TotalConnectTime>" | sed -e 's/<[^>]*>//g') #------------------------------ # Current Connect Time @@ -29,7 +25,7 @@ printf 'Current Connect Time : %d days: %02d hours: %02d minutes: %02d sseconds\ tct_secs=$TotalConnectTime printf 'Total Connect Time : %d days: %02d hours: %02d minutes: %02d sseconds\n' $((tct_secs / 86400)) $((tct_secs % 86400 / 3600)) $((tct_secs % 3600 / 60)) $((tct_secs % 60)) -#cat modem_status.xml +#cat $STATUS_FILE #------------------------------ # Current Upload #------------------------------ @@ -44,7 +40,7 @@ else fi #------------------------------ -# Current Downloae +# Current Download #------------------------------ if [ $CurrDownload -lt 1024 ]; then echo "Current Download : ${CurrDownload}B" |