1
0
mirror of https://github.com/byReqz/status.git synced 2024-11-21 23:33:14 +00:00

add colors

This commit is contained in:
Nils 2021-09-20 17:07:45 +02:00
parent c3c39ff446
commit 8bf526046b
Signed by: byreqz
GPG Key ID: 396A62D7D436749E

View File

@ -13,7 +13,18 @@ fi
function get_code { function get_code {
http_raw="$(curl -s -I $h | tr -d '\r')" http_raw="$(curl -s -I $h | tr -d '\r')"
http_code="[$(echo "$http_raw" | grep HTTP | cut -d " " -f 2)" http_code="$(echo "$http_raw" | grep HTTP | cut -d " " -f 2)"
if [[ "$http_code" < 299 && "$http_code" > 199 ]];then
http_code="[\e[32m"$http_code"\e[0m"
elif [[ "$http_code" < 199 && "$http_code" > 099 ]];then
http_code="[\e[36m"$http_code"\e[0m"
elif [[ "$http_code" < 399 && "$http_code" > 299 ]];then
http_code="[\e[1;33m"$http_code"\e[0m"
elif [[ "$http_code" < 499 && "$http_code" > 399 ]];then
http_code="[\e[1;31m"$http_code"\e[0m"
elif [[ "$http_code" < 599 && "$http_code" > 499 ]];then
http_code="[\e[31m"$http_code"\e[0m"
fi
http_server=" | $(echo "$http_raw" | grep Server: | cut -d " " -f 2)]" http_server=" | $(echo "$http_raw" | grep Server: | cut -d " " -f 2)]"
http_results=""$http_results" http_results=""$http_results"
$(printf "%-50s%s\n" ["$h"] "$http_code""$http_server")" $(printf "%-50s%s\n" ["$h"] "$http_code""$http_server")"
@ -23,12 +34,13 @@ function get_ping {
ping_raw="$(fping -e "$p" 2> /dev/null)" ping_raw="$(fping -e "$p" 2> /dev/null)"
ping_reach="$(echo "$ping_raw" | grep -o -e "alive" -e "unreachable")" ping_reach="$(echo "$ping_raw" | grep -o -e "alive" -e "unreachable")"
if [[ "$ping_reach" == "unreachable" ]];then if [[ "$ping_reach" == "unreachable" ]];then
ping_reach="[unreachable]" ping_reach="[\e[32munreachable\e[0m]"
elif [[ "$ping_reach" == "alive" ]];then elif [[ "$ping_reach" == "alive" ]];then
ping_reach="[alive" ping_reach="[\e[32malive\e[0m"
ping_ms=" | $(echo "$ping_raw" | cut -d "(" -f 2 | cut -d ")" -f 1)]" ping_ms=" | $(echo "$ping_raw" | cut -d "(" -f 2 | cut -d ")" -f 1)]"
else else
ping_reach="[error]" ping_reach="[error]"
ping_ms=""
fi fi
ping_results=""$ping_results" ping_results=""$ping_results"
$(printf "%-50s%s\n" ["$p]" "$ping_reach""$ping_ms")" $(printf "%-50s%s\n" ["$p]" "$ping_reach""$ping_ms")"
@ -38,11 +50,11 @@ if [[ "$ping_hosts" != "none" ]];then
for p in "${ping_hosts[@]}";do for p in "${ping_hosts[@]}";do
get_ping get_ping
done done
echo "$ping_results" echo -e "$ping_results"
fi fi
if [[ "$http_hosts" != "none" ]];then if [[ "$http_hosts" != "none" ]];then
for h in "${http_hosts[@]}";do for h in "${http_hosts[@]}";do
get_code get_code
done done
echo "$http_results" echo -e "$http_results"
fi fi