-
-
Save slmingol/529a1d5326a18781cf7c2ee838a3cedc to your computer and use it in GitHub Desktop.
Bash shell script to print stats about a Raspberry running pihole
This file contains 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/bash | |
# Define colors | |
RED='\033[91m' | |
RED_solid='\033[101m' | |
GREEN='\033[92m' | |
GREEN_solid='\033[42m' | |
CYAN='\033[96m' | |
NC='\033[0m' | |
BLUE_solid='\e[44m' | |
# Gather system details. | |
dt=$(date -R) | |
up=$(uptime) | |
gov=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor) | |
freq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq) | |
freq=$((freq/1000)) | |
usedRAM=$(free | awk '/Mem/{printf("%.2f\n"), $3/1024}') | |
freeRAM=$(free | awk '/Mem/{printf("%.2f\n"), $4/1024}') | |
cacheRAM=$(free | awk '/Mem/{printf("%.2f\n"), $6/1024}') | |
# temp=$(cat /sys/class/thermal/thermal_zone0/temp) ; temp=$((temp/1000)) | |
# measurements via vcgencmd, might require sudo access | |
volts=$(sudo /opt/vc/bin/vcgencmd measure_volts core | cut -d'=' -f 2) | |
temp=$(/opt/vc/bin/vcgencmd measure_temp | cut -d'=' -f 2 | cut -d"'" -f 1) | |
temp_check=$(printf %.0f $temp); temp_check=$((temp_check)); declare -i temp_check | |
# Print System details | |
echo -e "\n${GREEN_solid}$dt${NC}" | |
echo -e "\n${BLUE_solid}CPU${NC}" | |
echo -e "System voltage = $volts" | |
if ((temp_check >= 10 && temp_check <= 37)); then | |
echo -e "CPU temp=${GREEN}$temp°C${NC}" | |
fi | |
if ((temp_check > 37)); then | |
echo -e "CPU temp=${RED}$temp°C${NC}" | |
fi | |
if ((temp_check < 10)); then | |
echo -e "CPU temp=${CYAN}$temp°C${NC}" | |
fi | |
if [ "$gov" == "powersave" ]; then | |
echo -e "CPU Governor=${GREEN}$gov${NC}" | |
fi | |
if [ "$gov" == "conservative" ]; then | |
echo -e "CPU Governor=${CYAN}$gov${NC}" | |
fi | |
if [ "$gov" == "performance" ] | [ "$gov" == "ondemand" ]; then | |
echo -e "CPU Governor=${RED}$gov${NC}" | |
fi | |
if [ "$freq" == "700" ]; then | |
echo -e "Current speed=${GREEN}$freq MHz${NC}" | |
fi | |
if [ "$freq" == "1000" ]; then | |
echo -e "Current speed=${RED}$freq MHz${NC}" | |
fi | |
# Print free & used RAM | |
echo -e "\n${BLUE_solid}RAM${NC}" | |
echo -e "Free=${GREEN}$freeRAM MB${NC} ; Used=${RED}$usedRAM MB${NC}; Cache=${CYAN}$cacheRAM MB${NC}" | |
# print pihole status directly from pihole CLI | |
echo -e "\n${BLUE_solid}Pihole${NC}" | |
pihole status | |
# Check system status. | |
# Requires package dnsutils on linux. | |
echo -e "\n\n${BLUE_solid}Checking DNS resolution${NC}" | |
dig google.com +noall +stats +answer | |
# print system uptime | |
echo -e "${RED_solid} $up ${NC}" | |
# Potential alternatives | |
# temp=$(/opt/vc/bin/vcgencmd measure_temp | egrep -o '[0-9]*\.[0-9]*') | |
# freq=$(/opt/vc/bin/vcgencmd measure_clock arm | cut -d'=' -f 2) # in MHz | |
# freq=$((freq/1000000)) | |
# Troubleshooting: | |
# if you get the error "VCHI initialization failed" | |
# on running the above commands via vcgencmd, then you need | |
# to add your default "unprivilaged" user to the group 'video' | |
# Run: | |
# sudo usermod -G video piuser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment