To automate tasks or create some monitoring job we can use the older and efficient tool the “CronJob”.
For our example, I’ve created a simple script to detect the cache memory and clean it if raise to a condition then send a notification by mail.
Library used:
exim4 (mail server) or ssmtp (mail server). Both uses the same “mail” command. Script:
# grab the buff/cache memory mem="$(free -m | grep 'Mem:' | awk '{print $6}')" if (( $mem > 350 )) then echo 'wooo is more than 250M' echo 3 | sudo tee /proc/sys/vm/drop_caches echo 'cache dropped' echo "Memory buff/cache cleaned last value:" $mem | mail -s "cache_memory" target_mail@local....