Skip to content

Instantly share code, notes, and snippets.

@rahuldhole
Last active May 9, 2024 00:22
Show Gist options
  • Save rahuldhole/57e46cb9c22924fbd8b0e744d2c17540 to your computer and use it in GitHub Desktop.
Save rahuldhole/57e46cb9c22924fbd8b0e744d2c17540 to your computer and use it in GitHub Desktop.
CPU & RAM usage popup | Create a shortcut to call this script
#!/bin/bash
# Capture CPU usage
cpu_usage=$(top -bn2 | grep '%Cpu' | tail -1 | grep -P '(....|...) id,' | awk '{print 100-$8}')
# Capture memory usage
memory_usage=$(free -m | grep 'Mem:' | awk '{ print $3/$2*100 }')
# Display CPU and memory usage in a popup message using xmessage
echo -e "System Usage \nCPU Usage: $cpu_usage% \nMemory Usage: $memory_usage%"
echo -e "CPU Usage: $cpu_usage \nMemory Usage: $memory_usage%" | xmessage -center -title "System Usage" -file -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment