Skip to content

Instantly share code, notes, and snippets.

@alecdwm
Last active April 5, 2021 10:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alecdwm/07a23af95cf6d7564401af6d485a6e1a to your computer and use it in GitHub Desktop.
Save alecdwm/07a23af95cf6d7564401af6d485a6e1a to your computer and use it in GitHub Desktop.
A quick script to check whether your system's current memory usage could fit entirely inside its swap space
#!/bin/bash
# A quick script to check whether your system's current memory
# usage could fit entirely inside its swap space.
#
# Might be useful in determining the likelihood of a
# successful suspend to disk operation.
MEM_USED=$(free -m | grep Mem | awk '{print $3}')
SWAP_FREE=$(free -m | grep Swap | awk '{print $4}')
if [ ! $MEM_USED -lt $SWAP_FREE ]; then
printf "\x1b[31m✗\x1b[0m Mem Used: .$MEM_USED\n .Swap Free:.$SWAP_FREE\n"
exit 1
fi
printf "\x1b[32m✓\x1b[0m Mem Used: $MEM_USED\n Swap Free: $SWAP_FREE\n"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment