Skip to content

Instantly share code, notes, and snippets.

@seanhandley
Last active July 16, 2019 06:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanhandley/fb0907ba64bf4da413aff3e74cd0eaa3 to your computer and use it in GitHub Desktop.
Save seanhandley/fb0907ba64bf4da413aff3e74cd0eaa3 to your computer and use it in GitHub Desktop.
Display Info About Raspberry Pi
# Cheers to the original author https://www.raspberrypi.org/forums/viewtopic.php?t=23440
function pi_info_uptime() {
let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
printf "%d days, %d hours, %d minutes, %d seconds" "$days" "$hours" "$mins" "$secs"
}
function pi_info_clock_mhz() {
clock=`sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq`
clock_mhz=`expr ${clock} / 1000`
max_clock=`sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq`
throttled=`if [ $max_clock -gt $clock ]; then echo "(throttled)"; fi`
echo ${clock_mhz} Mhz ${throttled}
}
function pi_info_mem_used() {
mem_total=`cat /proc/meminfo | grep MemTotal | awk {'print $2'}`
mem_total_gb=`python -c "print round(${mem_total} / 1000000.0, 2)"`
mem_free=`cat /proc/meminfo | grep MemAvailable | awk {'print $2'}`
mem_free_gb=`python -c "print round(${mem_free} / 1000000.0, 2)"`
mem_used_gb=`python -c "print round((${mem_total} - ${mem_free}) / 1000000.0, 2)"`
echo ${mem_used_gb} / ${mem_total_gb}GB Used
}
function pi_info_temp() {
echo `/opt/vc/bin/vcgencmd measure_temp | cut -d'=' -f 2`
}
function pi_info_running_processes() {
echo `ps ax | wc -l | tr -d " "`
}
function pi_info_ip_address() {
echo `hostname -I | cut -d' ' -f 1`
}
function pi_info_wifi_strength() {
link_quality=`iwconfig wlan0 | grep "Link Quality" | cut -d"=" -f 2 | cut -d " " -f 1`
echo `python -c "print('%d%%' % round(${link_quality}.0 * 100))"`
}
function pi_info_free_disk_space() {
df -h | grep "^/dev" | while read line; do
drive=`echo $line | tr -s ' ' | cut -d' ' -f 6`
space=`echo $line | tr -s ' ' | cut -d' ' -f 4`
echo "${drive} (${space})"
done | tr -s "\n" "," | sed -e 's/,/, /g'
}
function pi_info_fan_status() {
status=`python -c "from fanshim import FanShim; print FanShim().get_fan()"`
if [ "$status" -eq "1" ]; then echo "on"; else echo "off"; fi
}
function pi_info() {
read one five fifteen rest < /proc/loadavg
echo "$(tput setaf 2)
.~~. .~~. `date +"%A, %e %B %Y, %r"`
'. \ ' ' / .' `uname -srmo`$(tput setaf 1)
.~ .~~~..~.
: .~.'~'.~. : Uptime.............: `pi_info_uptime`
~ ( ) ( ) ~ CPU................: Temp: `pi_info_temp`, Clock: `pi_info_clock_mhz`, Fan: `pi_info_fan_status`
( : '~'.~.'~' : ) Workload...........: Load: ${one}, ${five}, ${fifteen} (1, 5, 15 min), Running Processes: `pi_info_running_processes`
~ .~ ( ) ~. ~ Memory.............: `pi_info_mem_used`
( : '~' : ) Network............: IP: `pi_info_ip_address`, WiFi Strength: `pi_info_wifi_strength`
'~ .~~~. ~' Free Disk Space....: `pi_info_free_disk_space`
'~'
$(tput sgr0)"
}
pi_info
@seanhandley
Copy link
Author

seanhandley commented Jul 10, 2019

Tested on Raspberry Pi 4

Screenshot 2019-07-10 at 21 52 15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment