Reputation: 1
im still newbie at bash/ash ,can make this sysinfo more simple
# display info
machine_model=$(cat /proc/device-tree/model | tr -d "\000")
echo " ──────────────────────────────────────────────────"
printf " ====D-Net Gateway Link Information===="
echo ""
printf " Device Model: \x1B[94m%s\x1B[0m" "AN OPENWRT"
echo ""
printf " SoC: \x1B[94m%s\x1B[0m" "AMLogic(R)"
echo ""
printf " Builder: Ajie"
echo ""
printf " Kernel Info : \x1B[94m%s\x1B[0m" "$(uname -r)"
echo ""
display " Load" "${load%% *}" "${critical_load}" "0" "" "${load#* }"
echo ""
printf " Waktu aktif: \x1B[92m%s\x1B[0m" "$time"
echo ""
display " CPU Temp " "$cpu_tempx" "80" "0" "" "°C"
echo ""
if [ -x /usr/bin/cpustat ]; then
cpu_freq=$(/usr/bin/cpustat -F1500)
echo -n " CPU Freq: $cpu_freq"
else
echo ""
display " CPU Freq" "$cpu_freq" "1500" "0" " Mhz" ""
fi
echo ""
display " RAM" "$memory_usage" "70" "0" "%" " of ${memory_total}M"
echo ""
display " Swap Usage" "$swap_usage" "80" "0" "%" " of ${swap_total}M"
echo ""
display " Boot Storage" "$boot_usage" "90" "1" "%" " of $boot_total"
echo ""
display " ROOTFS" "$root_usage" "90" "1" "%" " of $root_total"
echo ""
echo " ──────────────────────────────────────────────────"
Output:
──────────────────────────────────────────────────
====D-Net Gateway Link Information====
Device Model: An OPENWRT
SoC: AMLogic(R)
Builder: Ajie
Kernel Info : 5.4.185
Load: 0.33 0.22 0.20
Active time: 2d 17h 54m 0s
CPU Temp : 41.0 °C
CPU Freq: 1512 Mhz
RAM: 32% of 1807M
Swap Usage: 19% of 902M
Boot Storage: 31% of 254.7M
ROOTFS: 52% of 7.0G
──────────────────────────────────────────────────
Full of the script https://raw.githubusercontent.com/AjieDevCorp-Limited/DNetG-WRT/master/sysco-v.19
I want to be like this ,
──────────────────────────────────────────────────
====D-Net Gateway Link Information====
Device Model: AN OPENWRT CPU Temp : 41.0 °C
SoC: AMLogic(R) CPU Freq: 1512 Mhz
Builder: Ajie RAM: 32% of 1807M
Kernel Info : 5.4.185 Swap Usage: 19% of 902M
Load: 0.33 0.22 0.20 Boot Storage: 31% of 254.7M
Active time: 2d 17h 54m 0s ROOTFS: 52% of 7.0G
──────────────────────────────────────────────────
or longer and horizontal
anyway i using Openwrt v21.02 the display info seems to fill the screen too much and it's annoying is there a way to solve this problem
Upvotes: -1
Views: 34
Reputation: 61
This question would actually be more appropriate over at https://codereview.stackexchange.com/ that being said. The echo "" commands are what is causing your output to show the way it is since echo will append a newline. To get more single wider lines of output you would combine two of your printfs into into a single printf statement and use \t to create the proper spacing. For example
pritnf " Device Model: \x1B[94m%s\x1B[0m" "AN OPENWRT\t SoC: \x1B[94m%s\x1B[0m" "AMLogic(R)\n"
The \t is for inserting tab characters and \n is for newlines. I would also run your script through https://www.shellcheck.net/
Upvotes: 0