Skip to content

Instantly share code, notes, and snippets.

@ftonato
Last active March 7, 2020 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ftonato/49ed346128c2f269093001fa086cbb44 to your computer and use it in GitHub Desktop.
Save ftonato/49ed346128c2f269093001fa086cbb44 to your computer and use it in GitHub Desktop.
./clearcache.sh < 1 | 2 | 3 >
#!/bin/bash
# Note, we are using "echo 3", but it is not recommended in production instead use "echo 1"
LEVEL=${1:-1} # If variable not set or null, use "1".
shift $(( $# > 0 ? 1 : 0 ))
# Check LEVEL is invalid then set to default "1"
if [ "$LEVEL" -gt 3 ]; then
LEVEL=1
fi
# 1 - Free pagecache, dentries and inodes in cache memory
# 2 - Free dentries and inodes use following command
# 3 - Free pagecache only use following command
echo "echo $LEVEL > /proc/sys/vm/drop_caches"
exit 0
@ftonato
Copy link
Author

ftonato commented Mar 7, 2020

# Clear Linux Memory Buffer Cache
0 17 * * FRI /usr/local/bin/clearcache.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment