Skip to content

Instantly share code, notes, and snippets.

@afunTW
Last active December 28, 2015 06:47
Show Gist options
  • Save afunTW/3a69fef1fca4d342bad0 to your computer and use it in GitHub Desktop.
Save afunTW/3a69fef1fca4d342bad0 to your computer and use it in GitHub Desktop.
dump memory usage per min
#!/bin/bash
echo "Recording memory usage to memoryLog..."
date >> memLog.csv
echo "USER,%CPU,%MEM,STIME,COMMAND" >> memLog.csv
while true; do
ps -ax -o user,pcpu,pmem,stime,cmd --sort -rss | head -n 6 >> tmpLog
while read -r user cpu mem stime cmd; do
if [ $user != "USER" ]; then
echo $user,$cpu,$mem,$stime,$cmd >> memLog.csv
fi
done < tmpLog
rm -f tmpLog
sleep 60
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment