Greatly improve status script

master
Skylar Ittner 6 years ago
parent a8753b3272
commit 8c55d0ca2c

@ -12,30 +12,74 @@ CLR='\e[0m'
INACTIVE="$RED[INACTIVE]$CLR" INACTIVE="$RED[INACTIVE]$CLR"
ACTIVE="$GRN[ACTIVE]$CLR" ACTIVE="$GRN[ACTIVE]$CLR"
function printline {
pad=$(printf '%0.1s' "."{1..60})
padlength=50
string1=$1
string2=$2
color=$3
clear='\e[0m'
printf '┃'
printf '%s ' "$string1"
printf '%*.*s' 0 $((padlength - ${#string1} - ${#string2} - 2 )) "$pad"
printf " $color%s$clear" "$string2"
printf '┃\n'
}
function printtextline {
pad=$(printf '%0.1s' " "{1..60})
padlength=50
string1=$1
string2=""
color=$3
clear='\e[0m'
printf '┃'
printf '%s ' "$string1"
printf '%*.*s' 0 $((padlength - ${#string1} - ${#string2} - 2 )) "$pad"
printf " $color%s$clear" "$string2"
printf '┃\n'
}
function printblank {
echo -e "┃ ┃"
}
function printdivider {
echo -e "┠──────────────────────────────────────────────────┨"
}
function printblankheader {
echo -e "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"
}
function printfooter {
echo -e '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛'
}
echo -e "$BLU" echo -e "$BLU"
toilet -f smblock.tlf "Netsyms Business" toilet -f smblock.tlf "Netsyms Business"
toilet -f smblock.tlf "Accelerator" toilet -f smblock.tlf "Accelerator"
echo -e "$CLR" echo -e "$CLR"
echo -e "---------------------------------------------------$WHT" printblankheader
echo -e "Engineered by$BLU Netsyms Technologies$CLR" printtextline "Engineered by Netsyms Technologies"
echo -e '' printblank
echo -e 'Home: https://netsyms.com' printtextline "Home: https://netsyms.com"
echo -e 'Support: https://support.netsyms.com' printtextline "Support: https://support.netsyms.com"
echo -e 'Source: https://source.netsyms.com' printtextline "Source: https://source.netsyms.com"
echo -e 'Business: https://netsyms.biz' printtextline "Business: https://netsyms.biz"
echo -e '---------------------------------------------------' printdivider
echo -e 'The programs included with this system are free' printtextline "The programs included with this system are free"
echo -e 'software; the exact distribution terms for each' printtextline "software; the exact distribution terms for each"
echo -e 'program are described in the individual files in' printtextline "program are described in the individual files in"
echo -e '/usr/share/doc/*/copyright.' printtextline "/usr/share/doc/*/copyright."
printfooter
echo -e '---------------------------------------------------'
upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)" upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
secs=$((${upSeconds}%60)) secs=$((${upSeconds}%60))
mins=$((${upSeconds}/60%60)) mins=$((${upSeconds}/60%60))
hours=$((${upSeconds}/3600%24)) hours=$((${upSeconds}/3600%24))
days=$((${upSeconds}/86400)) days=$((${upSeconds}/86400))
UPTIME=`printf "%02d days, %02dh %02dm" "$days" "$hours" "$mins"` UPTIME=`printf "%01d days, %02dh %02dm" "$days" "$hours" "$mins"`
freekb=$(cat /proc/meminfo | grep MemFree | awk {'print $2'}) freekb=$(cat /proc/meminfo | grep MemFree | awk {'print $2'})
totalkb=$(cat /proc/meminfo | grep MemTotal | awk {'print $2'}) totalkb=$(cat /proc/meminfo | grep MemTotal | awk {'print $2'})
@ -45,61 +89,64 @@ totalmb=$(($totalkb/1000))
percentfree=$(echo "scale=0; $freekb*100/$totalkb" | bc) percentfree=$(echo "scale=0; $freekb*100/$totalkb" | bc)
echo -e "Date .................................. $WHT$(date +%b\ %e\ %Y)$CLR" echo -e "┏━━━━━━━━━━━━━━━━━┥ System Info ┝━━━━━━━━━━━━━━━━━┓"
echo -e "Time ..................................... $WHT$(date +%H:%M:%S)$CLR" printline "Date" "$(date +%b\ %e\ %Y)" $WHT
echo -e "Uptime ........................... $WHT$UPTIME$CLR" printline "Time" "$(date +%H:%M:%S)" $WHT
echo -e "Processes ..................................... $WHT$(ps ax | wc -l | tr -d " ")$CLR" printline "Uptime" "$UPTIME" $WHT
echo -e "Load averages ....................$WHT$(uptime | awk -F'[a-z]:' '{ print $2}')$CLR" printline "Processes" "$(ps ax | wc -l | tr -d " ")" $WHT
printline "Load averages" "$(uptime | awk -F'[a-z]:' '{ print $2}')" $WHT
memcolor=$GRN
if (( $percentfree < 30 )); then if (( $percentfree < 30 )); then
echo -e "Memory used .......................... $RED$(($totalmb-$freemb)) MB ($((100-$percentfree))%)$CLR" memcolor=$RED
echo -e "Memory free .......................... $RED$freemb MB ($percentfree%)$CLR"
else
echo -e "Memory used .......................... $GRN$(($totalmb-$freemb)) MB ($((100-$percentfree))%)$CLR"
echo -e "Memory free .......................... $GRN$freemb MB ($percentfree%)$CLR"
fi fi
printline "Memory used" "$(($totalmb-$freemb)) MB ($((100-$percentfree))%)" $memcolor
printline "Memory free" "$freemb MB ($percentfree%)" $memcolor
cpu=$(</sys/class/thermal/thermal_zone0/temp) cpu=$(</sys/class/thermal/thermal_zone0/temp)
cpu=$((cpu/1000)) cpu=$((cpu/1000))
cpucolor=$GRN
if (( $cpu > 45 )); then if (( $cpu > 45 )); then
cpu="$RED$cpu\u00b0C$CLR" cpucolor=$RED
else
cpu="$GRN$cpu\u00b0C$CLR"
fi fi
echo -e "CPU temperature .............................. $cpu" printline "CPU temperature" "$cpu°C" $cpucolor
printfooter
# #
# Service Status # Service Status
# #
echo -e "┏━━━━━━━━━━━━━━━━━━━┥ Services ┝━━━━━━━━━━━━━━━━━━━┓"
if [ $(systemctl status cjdns.service | grep 'Active: ' | awk '{ print $2 }') = 'active' ]; then if [ $(systemctl status cjdns.service | grep 'Active: ' | awk '{ print $2 }') = 'active' ]; then
echo -e "cjdns Service ............................ $ACTIVE" printline "CJDNS Service" "[RUNNING]" $GRN
else else
echo -e "cjdns Service .......................... $INACTIVE" printline "CJDNS Service" "[STOPPED]" $RED
fi fi
if [ $(systemctl status nginx.service | grep 'Active: ' | awk '{ print $2 }') = 'active' ]; then if [ $(systemctl status nginx.service | grep 'Active: ' | awk '{ print $2 }') = 'active' ]; then
echo -e "nginx Service ............................ $ACTIVE" printline "NGINX Service" "[RUNNING]" $GRN
else else
echo -e "nginx Service .......................... $INACTIVE" printline "NGINX Service" "[STOPPED]" $RED
fi fi
if [ $(systemctl status php7.0-fpm.service | grep 'Active: ' | awk '{ print $2 }') = 'active' ]; then PHP_VERSION=$(php -v | head -n 1 | cut -c5-7)
echo -e "php-fpm Service .......................... $ACTIVE" if [ $(systemctl status php$PHP_VERSION-fpm.service | grep 'Active: ' | awk '{ print $2 }') = 'active' ]; then
printline "PHP $PHP_VERSION Service" "[RUNNING]" $GRN
else else
echo -e "php-fpm Service ........................ $INACTIVE" printline "PHP $PHP_VERSION Service" "[STOPPED]" $RED
fi fi
printfooter
# #
# IP/Network Info # IP/Network Info
# #
LOCAL_IP=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')
echo -e "---------------------------------------------------$WHT" PUBLIC_IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
echo -e "Local IP$CLR" CJDNS_IP=$(sudo grep -m 1 '"ipv6"' /etc/cjdroute.conf | awk '{ print $2 }' | sed 's/[",]//g')
ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' echo -e "┏━━━━━━━━━━━━━━━━━┥ Network Info ┝━━━━━━━━━━━━━━━━━┓"
echo -e "---------------------------------------------------$WHT" printline "Local" "$LOCAL_IP" $WHT
echo -e "Public IP$CLR" printline "Public" "$PUBLIC_IP" $WHT
dig +short myip.opendns.com @resolver1.opendns.com printline "CJDNS" "$CJDNS_IP" $WHT
echo -e "---------------------------------------------------$WHT" printdivider
echo -e "CJDNS IP$CLR" printtextline "For network bandwidth usage data, run vnstat"
sudo grep -m 1 '"ipv6"' /etc/cjdroute.conf | awk '{ print $2 }' | sed 's/[",]//g' printfooter
echo -e '---------------------------------------------------'
echo -e "For network bandwidth usage data, run$WHT vnstat$CLR"
echo -e "To refresh this status message, run$WHT status$CLR"
#vnstat -i eth0+tun0+wlan0 --style 0 #vnstat -i eth0+tun0+wlan0 --style 0
echo -e '---------------------------------------------------'

Loading…
Cancel
Save