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

Loading…
Cancel
Save