Skip to content

Instantly share code, notes, and snippets.

@lappemic
Created June 25, 2024 15:20
Show Gist options
  • Save lappemic/e127250640d725507391af846e0c371f to your computer and use it in GitHub Desktop.
Save lappemic/e127250640d725507391af846e0c371f to your computer and use it in GitHub Desktop.
Bash script to log memory usage every minute for three hours
#!/bin/bash
# install bc (cli calculator):
# sudo apt-get install bc
# and make script executable:
# chmod +x log_memory.sh
# Create or clear the usage.txt file
> memory_usage.txt
# Loop to log memory usage every minute for three hours
for i in `seq 0 180`; do
active_kb=$(cat /proc/meminfo | grep Active: | sed 's/Active: *//g' | awk '{print $1}')
total_kb=$(cat /proc/meminfo | grep MemTotal: | sed 's/MemTotal: *//g' | awk '{print $1}')
active_gb=$(echo "scale=2; $active_kb / 1024 / 1024" | bc)
total_gb=$(echo "scale=2; $total_kb / 1024 / 1024" | bc)
echo "$active_gb/$total_gb GB" >> memory_usage.txt
sleep 1m
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment