Skip to content

Instantly share code, notes, and snippets.

@MagedSaeed
Last active January 1, 2023 16:32
Show Gist options
  • Save MagedSaeed/fcf2a95d9d436a937f11d59b6c53905d to your computer and use it in GitHub Desktop.
Save MagedSaeed/fcf2a95d9d436a937f11d59b6c53905d to your computer and use it in GitHub Desktop.
Monitor resources from bash
#!/bin/bash
# This script monitors CPU and memory usage
# Get the current usage of CPU and memory
cpuUsage=$(top -bn1 | awk '/Cpu/ { print $2}')
memUsage=$(free -m | awk '/Mem/{print $3}')
# Print the usage
echo "CPU Usage: $cpuUsage%"
printf "Memory Usage: %'d MB\n" $memUsage
echo "GPU STATS (this requires pip install gpustat):"
gpustat
# save this code to monitor_resources.bash and run: `watch -n 1 monitor_resources.bashs` to update every second
# This has been updated from:
# https://linuxconfig.org/bash-script-to-monitor-cpu-and-memory-usage-on-linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment