Created
July 8, 2024 14:06
-
-
Save Bludwarf/345f1668ee83f5df0975c392085d61cb to your computer and use it in GitHub Desktop.
Script to log top 10 %mem processes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAILTO='' | |
*/5 * * * * ~/ps.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Log top 10 processes ordered by memory consumption | |
sudo ps -ax -o pid,%cpu,rss,user --sort=-rss | head -n11 | tail -n10 | sed "s/^/$(date '+%Y-%m-%d %H:%M:%S'): /" >> ps.log | |
# Limit log file size | |
tail -n1000 ps.log | sponge ps.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source for log rotation : https://unix.stackexchange.com/a/310873/110588.