From c1cb865e619d169ae48c0d5c83a4df93305dc8f0 Mon Sep 17 00:00:00 2001 From: Teddysun Date: Wed, 23 Sep 2015 10:04:56 +0800 Subject: [PATCH] Pretty display --- bench.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bench.sh b/bench.sh index 99821ce..423c782 100644 --- a/bench.sh +++ b/bench.sh @@ -14,13 +14,23 @@ swap=$( free -m | awk 'NR==4 {print $2}' ) up=$( awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60;d=$1%60} {printf("%ddays, %d:%d:%d\n",a,b,c,d)}' /proc/uptime ) next() { - printf "%-60s\n" "-" | sed 's/\s/-/g' + printf "%-70s\n" "-" | sed 's/\s/-/g' } speed_test() { speedtest=$(wget -4O /dev/null $1 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}') ipaddress=$(ping -c1 `awk -F'/' '{print $3}' <<< $1` | awk -F'[()]' '{print $2;exit}') - echo -e "Download speed from \e[33m$2\e[0m(IP:\e[32m$ipaddress\e[0m): \e[31m$speedtest\e[0m" + nodeName=$2 + if [ "${#nodeName}" -lt "8" ]; then + echo -e "\e[33m$2\e[0m\t\t\t\t\e[32m$ipaddress\e[0m\t\t\e[31m$speedtest\e[0m" + elif [ "${#nodeName}" -lt "13" ]; then + echo -e "\e[33m$2\e[0m\t\t\t\e[32m$ipaddress\e[0m\t\t\e[31m$speedtest\e[0m" + elif [ "${#nodeName}" -lt "24" ]; then + echo -e "\e[33m$2\e[0m\t\t\e[32m$ipaddress\e[0m\t\t\e[31m$speedtest\e[0m" + elif [ "${#nodeName}" -ge "24" ]; then + echo -e "\e[33m$2\e[0m\t\e[32m$ipaddress\e[0m\t\t\e[31m$speedtest\e[0m" + fi + #echo -e "Download speed from \e[33m$2\e[0m(IP:\e[32m$ipaddress\e[0m): \e[31m$speedtest\e[0m" } speed() { @@ -52,6 +62,7 @@ echo "System uptime : $up" next if [ -e '/usr/bin/wget' ]; then + echo -e "Node Name\t\t\tNode IP address\t\tDownload Speed" speed && next else echo "Error: wget command not found. You must be install wget command at first."