Skip to content

Instantly share code, notes, and snippets.

@ckunte
Last active September 13, 2024 11:53
Show Gist options
  • Save ckunte/e0cb5d49a4baf9f9a9fef67052bf112d to your computer and use it in GitHub Desktop.
Save ckunte/e0cb5d49a4baf9f9a9fef67052bf112d to your computer and use it in GitHub Desktop.
Raspberry Pi sysinfo function
#!/bin/bash
# Define the function
display_system_info() {
# Set column width (adjust as needed)
local column_width=18
# Define a function to print data in a four-column format
print_table() {
local col1="$1"
local col2="$2"
local col3="$3"
local col4="$4"
printf "%-${column_width}s %-${column_width}s %-${column_width}s %s\n" "$col1" "$col2" "$col3" "$col4"
}
# Collect data
mem=$(free -h | awk '/Mem:/ {print $3 "/" $2}')
dsk=$(df -h | awk '/\/$/ {print $3 "/" $2}')
tem="$(vcgencmd measure_temp | grep -o -E '[[:digit:]].*')"
pow="$(vcgencmd measure_volts | sed 's/volt=//g')"
ipa=$(hostname -I | awk '{print $1}')
upt=$(uptime -p | sed 's/^up //')
# Print the table with four columns
print_table "Board temp:" "$tem" "Disk use:" "$dsk"
print_table "IP address:" "$ipa" "Mem. use:" "$mem"
print_table "Power cons:" "$pow" " Uptime:" "$upt"
}
# To use the function, call it like this:
#display_system_info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment