Created
October 6, 2022 01:16
-
-
Save kode54/f66aeadcddca471ed7a469e98e568f1c to your computer and use it in GitHub Desktop.
Swap Info script for bash, not originally mine
This file contains 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
#!/bin/bash | |
overall=0 | |
outlist="" | |
for status_file in /proc/[0-9]*/status; do | |
swap_mem=$(grep VmSwap "$status_file" | awk '{ print $2 }') | |
if [ "$swap_mem" ] && [ "$swap_mem" -gt 0 ]; then | |
pid=$(grep Tgid "$status_file" | awk '{ print $2 }') | |
name=$(grep Name "$status_file" | awk '{ print $2 }') | |
printf -v output "%s\t%s\t%s KB\n" "$pid" "$name" "$swap_mem" | |
outlist="$outlist$output" | |
fi | |
overall=$((overall+swap_mem)) | |
done | |
printf "%s" "$outlist" | sort -k 3 -n -r | |
printf "Total Swapped Memory: %14u KB\n" $overall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment