Last active
November 6, 2025 08:33
-
-
Save devicezero/d0ab8cfac6af12b7f0b8baf276966a49 to your computer and use it in GitHub Desktop.
basic system info (cpu, memory, storage)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| echo "{" | |
| ### CPU ### | |
| echo "\"cpu\": {" | |
| cpu_name=$(grep -m1 -E 'Model|Hardware|model name|Processor' /proc/cpuinfo | awk -F': ' '{print $2}') | |
| [ -z "$cpu_name" ] && cpu_name="unknown" | |
| cpu_cores=$(grep -c '^processor' /proc/cpuinfo 2>/dev/null) | |
| [ -z "$cpu_cores" ] && cpu_cores=1 | |
| printf "\"name\": \"%s\",\n" "$cpu_name" | |
| printf "\"cores\": %s\n" "$cpu_cores" | |
| echo "}," | |
| ### Memory ### | |
| echo "\"memory\": {" | |
| mem_total=$(grep MemTotal /proc/meminfo | awk '{print $2}') | |
| mem_avail=$(grep MemAvailable /proc/meminfo | awk '{print $2}') | |
| [ -z "$mem_avail" ] && mem_avail=0 | |
| printf "\"total_kb\": %s,\n" "$mem_total" | |
| printf "\"available_kb\": %s\n" "$mem_avail" | |
| echo "}," | |
| ### Storage ### | |
| echo "\"storage\": [" | |
| df -B1 -P | awk 'NR==1{next} { | |
| if (n++) printf(",\n"); | |
| printf("{\"filesystem\":\"%s\",\"size_bytes\":%s,\"used_bytes\":%s,\"avail_bytes\":%s,\"mount\":\"%s\"}", | |
| $1,$2,$3,$4,$6) | |
| }' | |
| echo "]" | |
| echo "}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment