Skip to content

Instantly share code, notes, and snippets.

@alekrutkowski
Created June 17, 2023 19:51
Show Gist options
  • Save alekrutkowski/b2bd9d485ef6858d5126d092b5775ee7 to your computer and use it in GitHub Desktop.
Save alekrutkowski/b2bd9d485ef6858d5126d092b5775ee7 to your computer and use it in GitHub Desktop.
A bash script to add RAM usage percent as a new item in the XFCE panel
#!/bin/bash
# Prerequisities
# 0) XFCE
# 1) Save this script in your home directory as: /home/your_user_name/calculate_ram_usage.sh
# 2) Add a new XFCE Generic Monitor Applet item (with the settings: no label, 1 second refresh period): /home/your_user_name/calculate_ram_usage.sh
output=$(free)
# Use grep with perl-regex (-P) to extract numbers and store them in an array
numbers=($(echo "$output" | grep -oP '\d+'))
# Extract the first and the sixth numbers
total=${numbers[0]}
available=${numbers[5]}
# Divide the numbers
result=$(echo "scale=0; 100*($total - $available)/$total" | bc)
echo "$result%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment