#!/bin/bash # # 30-sysinfo - generate the system information # Copyright (c) 2015 Igor Pecovnik # define which hard drive you want to monitor storage=/dev/sda1 # don't edit below here function displaytime { # we need dedicated function local T=$(cat /proc/uptime | awk '{print $1}' | sed 's/[.].*//') local D=$((T/60/60/24)) local H=$((T/60/60%24)) local M=$((T/60%60)) local S=$((T%60)) local time=$S time=$S" sec" (( $M > 0 )) && time=$M" min" (( $H > 0 )) && time=$H" hour" (( $H > 1 )) && time=$H" hours" (( $D > 0 )) && time=$D" day" (( $D > 1 )) && time=$D" days" printf "Up time: " printf "\x1B[92m%s\x1B[0m\t\t" "$time" } function display() { # $1=name $2=value $3=red_limit $4=minimal_show_limit $5=unit $6=after $7=acs/desc{ # battery red color is opposite, lower number if [[ "$1" == "Battery" ]]; then local great="<"; else local great=">"; fi if [[ -n "$2" && "$2" > "0" && (( "${2%.*}" -ge "$4" )) ]]; then printf "%-14s%s" "$1:" if (( $(echo "$2 $great $3" | bc -l) )); then echo -ne "\e[0;91m $2"; else echo -ne "\e[0;92m $2"; fi printf "%-1s%s\x1B[0m" "$5" printf "%-11s%s\t" "$6" return 1 fi } # Battery info for Allwinner # kernel 4.4+ axp_dir="/sys/power/axp_pmu" if [[ -e "$axp_dir" ]]; then status_battery_connected=$(cat $axp_dir/battery/connected) if [[ "$status_battery_connected" == "1" ]]; then status_battery_charging=$(cat $axp_dir/charger/charging) status_ac_connect=$(cat $axp_dir/ac/connected) battery_percent=$(cat $axp_dir/battery/capacity) # dispay charging / percentage if [[ "$status_ac_connect" == "1" && "$battery_percent" -lt "100" ]]; then status_battery_text=" charging" elif [[ "$status_ac_connect" == "1" && "$battery_percent" -eq "100" ]]; then status_battery_text=" charged" else status_battery_text=" discharging" fi fi fi # legacy kernel axp_dir="/sys/class/power_supply" if [[ -e "$axp_dir" && -e "$axp_dir/battery" ]]; then if [[ (("$(cat $axp_dir/battery/voltage_now)" -gt "5" )) ]]; then status_battery_text=" "$(cat $axp_dir/battery/status | awk '{print tolower($0)}') battery_percent=$(cat $axp_dir/battery/capacity) fi fi load=$(cat /proc/loadavg | awk '{print $1}') memory_usage=$(free | awk '/Mem/ {printf("%.0f",(($2-($4+$6+$7))/$2) * 100)}') memory_total=$(free -m | awk '/Mem/ {print $(2)}') users=$(users | wc -w) swap_total=$(free -m | awk '/Swap/ { printf("%3.0f", $3/$2*100) }' | sed 's/ //g') swap_usage=${swap_usage//[!0-9]/} # to remove alfanumeric if swap not used swap_total=$(free -m | awk '/Swap/ {print $(2)}') ip_address=$((ifconfig -a) | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p' | head -1) root_usage=$(df -h / | awk '/\// {print $(NF-1)}' | sed 's/%//g') root_total=$(df -h / | awk '/\// {print $(NF-4)}') if [ -e "$storage" ]; then storage_usage=$(df -h $storage | grep $storage | awk '/\// {print $(NF-1)}' | sed 's/%//g') storage_total=$(df -h $storage | grep $storage | awk '/\// {print $(NF-4)}') [[ "$storage" == */sd* ]] && hdd_temp=$(hddtemp -u C -nq $storage) fi # read temperature from different locations mkdir -p -m775 /etc/armbianmonitor/datasources/ # from axp via i2c for some old sunxi if [ -d "/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/" ]; then board_temp=$(awk '{printf("%d",$1/1000)}' 0 )) && echo "" # new line only if some value is displayed display "Usage of /" "$root_usage" "90" "1" "%" " of $root_total" display "storage/" "$storage_usage" "90" "1" "%" " of $storage_total" display "Battery" "$battery_percent" "20" "1" "%" "$status_battery_text" echo "" echo ""