Skip to content

Instantly share code, notes, and snippets.

@jbdrvl
Created January 9, 2019 19:09
Show Gist options
  • Select an option

  • Save jbdrvl/b57db19b86288c19c02f8db843d9bf7b to your computer and use it in GitHub Desktop.

Select an option

Save jbdrvl/b57db19b86288c19c02f8db843d9bf7b to your computer and use it in GitHub Desktop.
Prints some information about the system: battery level, disk/mem/swap usage and CPU temperature
#!/usr/bin/env sh
# Jan 9, 2019
# Debian 4.17
echo Battery Status:
awk "BEGIN {printf \"%.1f%%\n\n\", 100*$(cat /sys/class/power_supply/BAT0/energy_now)/$(cat /sys/class/power_supply/BAT0/energy_full)}"
echo 'CPU Temperature (Celsius):'
echo "$(($(cat /sys/class/thermal/thermal_zone0/temp)/1000)) C\n"
echo Memory Usage:
awk "BEGIN {printf \"%.1f%%\n\n\", 100*(1-($(head -n 3 /proc/meminfo | tail -n 1 | egrep -o '[0-9]+')/$(head -n 1 /proc/meminfo | egrep -o '[0-9]+')))}"
echo SWAP Usage:
tail -n +2 /proc/swaps | awk '{printf "%s %.1f%%\n", $1, $4/$3}'
echo
echo Disk Usage:
df | awk '{if ($6=="/"){print $1,$5}}'
@jbdrvl
Copy link
Author

jbdrvl commented Jan 14, 2019

The temperature one does not always work, since the file (/sys/class/thermal/thermal_zone0/temp) might not be there on all systems (for example in some VMs)

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