From 003a32b4a2bdd9df0910ecbfa976aa8b885896f7 Mon Sep 17 00:00:00 2001 From: Slava Date: Tue, 14 Jan 2020 02:18:46 +0300 Subject: [PATCH] Rework for modular system Autoadd disks to temps (only for sd*, and works on smartmontools) Some cosmetic changes --- 10-display-name | 7 +++++-- 20-sysinfo | 19 +++++++------------ 30-hdd-free | 12 +++++++----- 30-hdd-temp | 35 +++++++++++++++++++++-------------- 40-services | 9 +++++---- 60-docker | 7 ++++--- 6 files changed, 49 insertions(+), 40 deletions(-) diff --git a/10-display-name b/10-display-name index ac8b8ac..5b9c7cb 100755 --- a/10-display-name +++ b/10-display-name @@ -1,3 +1,6 @@ #!/bin/bash - -figlet -k -f slant "$(hostname)" +color="\e[1;33m" +clear="\e[m" +echo -e ${color} +figlet -k -f slant $(hostname) +echo -e ${clear} diff --git a/20-sysinfo b/20-sysinfo index c5467cf..951f169 100755 --- a/20-sysinfo +++ b/20-sysinfo @@ -1,7 +1,5 @@ #!/bin/bash -# get load averages -IFS=" " read LOAD1 LOAD5 LOAD15 <<<$(/bin/cat /proc/loadavg | awk '{ print $1,$2,$3 }') # get free memory IFS=" " read USED FREE TOTAL <<<$(free -htm | grep "Mem" | awk {'print $3,$4,$2'}) # get processes @@ -11,16 +9,13 @@ PROCESS_ROOT=`echo "$PROCESS"| grep root | awk {'print $2'}` PROCESS_USER=`echo "$PROCESS"| grep -v root | awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'` W="\e[0;39m" -G="\e[1;32m" +G="\e[1;33m" echo -e " ${W}system info: -$W Distro......: $W`cat /etc/*release | grep "PRETTY_NAME" | cut -d "=" -f 2- | sed 's/"//g'` -$W Kernel......: $W`uname -sr` - -$W Uptime......: $W`uptime -p` -$W Load........: $G$LOAD1$W (1m), $G$LOAD5$W (5m), $G$LOAD15$W (15m) -$W Processes...:$W $G$PROCESS_ROOT$W (root), $G$PROCESS_USER$W (user) | $G$PROCESS_ALL$W (total) - -$W CPU.........: $W`cat /proc/cpuinfo | grep "model name" | cut -d ' ' -f3- | awk {'print $0'} | head -1` -$W Memory......: $G$USED$W used, $G$FREE$W free, $G$TOTAL$W in total$W" +$W Uptime.: $W`uptime -p | awk '{if ($1 != "test") printf("%s %s %s %s\n", $2, $3, $4, $5); }' | sed 's/,//g'` +$W Distro.: $W`cat /etc/*release | grep "PRETTY_NAME" | cut -d "=" -f 2- | sed 's/"//g'` +$W Kernel.: $W`uname -sr` +$W Proc...: $W$G$PROCESS_ROOT$W (r), $G$PROCESS_USER$W (u) | $G$PROCESS_ALL$W (t) +$W CPU....:$W`cat /proc/cpuinfo | grep "name" | cut -d : -f2 | uniq | cut -f1 -d"@" | sed 's/(TM)//;s/(R)//;s/CPU//'` +$W Memory.: $G$USED$W used | $G$TOTAL$W in total$W" diff --git a/30-hdd-free b/30-hdd-free index 63995f9..72e9b04 100755 --- a/30-hdd-free +++ b/30-hdd-free @@ -1,7 +1,7 @@ #!/bin/bash -mountpoints=('/mnt/sdb1' '/' '/mnt/backup/') -barWidth=50 +mountpoints=('/dev/sdf1' '/dev/vg1/downloads' '/dev/sdb1') +barWidth=34 maxDiscUsage=90 clear="\e[39m\e[0m" dim="\e[2m" @@ -10,10 +10,11 @@ echo echo 'HDD free:' for point in "${mountpoints[@]}"; do line=$(df -hl "${point}") + label=$(lsblk -o label "${point}") usagePercent=$(echo "$line"|tail -n1|awk '{print $5;}'|sed 's/%//') usedBarWidth=$((($usagePercent*$barWidth)/100)) barContent="" - color="\e[32m" + color="\e[33m" if [ "${usagePercent}" -ge "${maxDiscUsage}" ]; then color="\e[31m" fi @@ -26,7 +27,8 @@ for point in "${mountpoints[@]}"; do barContent="${barContent}-" done bar="[${barContent}${clear}]" - echo "${line}" | awk '{if ($1 != "Filesystem") printf("%-30s%+3s used out of %+5s\n", $1, $3, $2); }' | sed -e 's/^/ /' - echo -e "${bar}" | sed -e 's/^/ /' + echo "${label}" | awk '{if ($1 != "LABEL") printf("%-10s", $1); }' + echo "${line}" | awk '{if ($1 != "Filesystem") printf("%+8s used out of %+5s\n", $3, $2); }' + echo -e "${bar}" done diff --git a/30-hdd-temp b/30-hdd-temp index 7c3b9e3..03fd0ad 100755 --- a/30-hdd-temp +++ b/30-hdd-temp @@ -1,23 +1,30 @@ #!/bin/bash -sd=(sda) +disks=${disks:-()} out="" +dim="\e[43m" +white="\e[31m" +label="\e[1;30m" COLUMNS=3 clear="\e[0m\e[39m" - my_target_temp=45 -for i in ${!sd[@]}; do - temp=$(smartctl -a /dev/${sd[$i]} | grep Temperature_Celsius | grep 194 | awk '{print $10}' 2> /dev/null) +k=0 + +for i in {a..z}; do + temp=$(smartctl -a /dev/sd${i} | grep Temperature_Celsius | grep 194 | awk '{print $10}' 2> /dev/null) color="\e[42m" - if [ "$temp" -ge "${my_target_temp}" ]; then - color="\e[41m" + ((k++)) + if [ -z "$temp" ]; then + out+="" + else + if [ "$temp" -ge "${my_target_temp}" ]; then + color="\e[41m" + fi + out+="${dim}${white}${label} sd${i} \e[30m$color $temp $clear," + if [ $(($k % $COLUMNS)) -eq 0 ]; then + out+="\n" + fi fi - out+="${sd[$i]} \e[30m $color $temp $clear ," - c=i+1 - if [ $((($i+1) % $COLUMNS)) -eq 0 ]; then - out+="\n" - fi done out+="\n" -echo -e " -HDD Temps:" -printf "$out" | column -c $c -ts $',' | sed -e 's/^/ /' +echo -e "HDD Temps:" +printf "$out" | column -c $k -ts $',' | sed -e 's/^/ /' diff --git a/40-services b/40-services index e917fc0..1b7a5f2 100755 --- a/40-services +++ b/40-services @@ -1,12 +1,13 @@ #!/bin/bash +export LANG='en_US.UTF-8' # set column width -COLUMNS=3 +COLUMNS=2 # colors green="\e[1;32m" red="\e[1;31m" undim="\e[0m" -services=( "smartd" "plexmediaserver" "docker" "smdb") +services=( "smartd" "plexmediaserver" "docker" "smbd") # sort services IFS=$'\n' services=($(sort <<<"${services[*]}")) unset IFS @@ -20,9 +21,9 @@ done for i in ${!services[@]}; do # color green if service is active, else red if [[ "${service_status[$i]}" == "active" ]]; then - out+="${services[$i]}:,${green}${service_status[$i]}${undim}," + out+="${services[$i]}:,${green}▲${undim}," else - out+="${services[$i]}:,${red}${service_status[$i]}${undim}," + out+="${services[$i]}:,${red}▼${undim}," fi # insert \n every $COLUMNS column if [ $((($i+1) % $COLUMNS)) -eq 0 ]; then diff --git a/60-docker b/60-docker index 06cc052..38e3d11 100755 --- a/60-docker +++ b/60-docker @@ -1,5 +1,6 @@ #!/bin/bash +export LANG='en_US.UTF-8' # set column width COLUMNS=2 # colors @@ -17,9 +18,9 @@ for i in "${!containers[@]}"; do IFS=" " read name status <<< ${containers[i]} # color green if service is active, else red if [[ "${status}" == "Up" ]]; then - out+="${name}:,${green}${status,,}${undim}," + out+="${name}:,${green}▲${undim}," else - out+="${name}:,${red}${status,,}${undim}," + out+="${name}:,${red}▼${undim}," fi # insert \n every $COLUMNS column if [ $((($i+1) % $COLUMNS)) -eq 0 ]; then @@ -29,4 +30,4 @@ done out+="\n" printf "\nDocker status:\n" -printf "$out" | column -ts $',' | sed -e 's/^/ /' +printf "$out" | column -ts $',' | sed -e 's/^/ /'