summaryrefslogtreecommitdiff
path: root/e3372-stats.sh
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2021-03-22 23:11:46 +0300
committerEvgeny Zinoviev <me@ch1p.io>2021-03-22 23:11:46 +0300
commit56df129e9de9022c2aa01717a784d94e1374115e (patch)
treea426b8f2ea71ebcf1350ac2e9a271079e9537797 /e3372-stats.sh
parentefe41f5ce1c1023af96d06c19f5d4f91957d26b5 (diff)
code refactoring
Diffstat (limited to 'e3372-stats.sh')
-rwxr-xr-xe3372-stats.sh43
1 files changed, 19 insertions, 24 deletions
diff --git a/e3372-stats.sh b/e3372-stats.sh
index 19f560a..43e52e4 100755
--- a/e3372-stats.sh
+++ b/e3372-stats.sh
@@ -1,17 +1,14 @@
#!/bin/bash
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
+DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
. "$DIR/config.sh"
-curl -s -X GET "http://$MODEM_IP/api/webserver/SesTokInfo" > ses_tok.xml
-COOKIE=`grep "SessionID=" ses_tok.xml | cut -b 10-147`
-TOKEN=`grep "TokInfo" ses_tok.xml | cut -b 10-41`
+get_token
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
-
+ -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')
@@ -24,13 +21,13 @@ TotalConnectTime=$(cat modem_status.xml | grep "<TotalConnectTime>" | sed -e 's/
# Current Connect Time
#------------------------------
cct_secs=$CurConnTime
-printf 'Current Connect Time : %d days: %02d hours: %02d minutes: %02d sseconds\n' $((cct_secs/86400)) $((cct_secs%86400/3600)) $((cct_secs%3600/60)) $((cct_secs%60))
+printf 'Current Connect Time : %d days: %02d hours: %02d minutes: %02d sseconds\n' $((cct_secs / 86400)) $((cct_secs % 86400 / 3600)) $((cct_secs % 3600 / 60)) $((cct_secs % 60))
#------------------------------
# Total Connect Time
#------------------------------
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))
+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
#------------------------------
@@ -39,11 +36,11 @@ printf 'Total Connect Time : %d days: %02d hours: %02d minutes: %02d sseconds\n'
if [ $CurrUpload -lt 1024 ]; then
echo "Current Upload : ${CurrUpload}B"
elif [ $CurrUpload -lt 1048576 ]; then
- echo "Current Upload : $((CurrUpload/1024))KiB"
+ echo "Current Upload : $((CurrUpload / 1024))KiB"
elif [ $CurrUpload -lt 1073741824 ]; then
- echo "Current Upload : $((CurrUpload/1048576))MiB"
+ echo "Current Upload : $((CurrUpload / 1048576))MiB"
else
- echo "Current Upload : $((CurrUpload/1073741824))GiB"
+ echo "Current Upload : $((CurrUpload / 1073741824))GiB"
fi
#------------------------------
@@ -52,11 +49,11 @@ fi
if [ $CurrDownload -lt 1024 ]; then
echo "Current Download : ${CurrDownload}B"
elif [ $CurrDownload -lt 1048576 ]; then
- echo "Current Download : $((CurrDownload/1024))KiB"
+ echo "Current Download : $((CurrDownload / 1024))KiB"
elif [ $CurrDownload -lt 1073741824 ]; then
- echo "Current Download : $((CurrDownload/1048576))MiB"
+ echo "Current Download : $((CurrDownload / 1048576))MiB"
else
- echo "Current Dowbload : $((CurrDownload/1073741824))GiB"
+ echo "Current Dowbload : $((CurrDownload / 1073741824))GiB"
fi
#------------------------------
@@ -65,11 +62,11 @@ fi
if [ $TotalUpload -lt 1024 ]; then
echo "Total Upload : ${TotalUpload}B"
elif [ $TotalUpload -lt 1048576 ]; then
- echo "Total Upload : $((TotalUpload/1024))KiB"
+ echo "Total Upload : $((TotalUpload / 1024))KiB"
elif [ $TotalUpload -lt 1073741824 ]; then
- echo "Total Upload : $((TotalUpload/1048576))MiB"
+ echo "Total Upload : $((TotalUpload / 1048576))MiB"
else
- echo "Total Upload : $((TotalUpload/1073741824))GiB"
+ echo "Total Upload : $((TotalUpload / 1073741824))GiB"
fi
#------------------------------
@@ -78,11 +75,9 @@ fi
if [ $TotalDownload -lt 1024 ]; then
echo "Total Download : ${TotalDownload}B"
elif [ $TotalDownload -lt 1048576 ]; then
- echo "Total Download : $((TotalDownload/1024))KiB"
+ echo "Total Download : $((TotalDownload / 1024))KiB"
elif [ $TotalDownload -lt 1073741824 ]; then
- echo "Total Download : $((TotalDownload/1048576))MiB"
+ echo "Total Download : $((TotalDownload / 1048576))MiB"
else
- echo "Total Doenload : $((TotalDownload/1073741824))GiB"
+ echo "Total Doenload : $((TotalDownload / 1073741824))GiB"
fi
-
-