Nettoyage cache auto dans linux

    0

    0

    linuxbashcache•••

    This code will display the amount of RAM and swap used on the system It will then clear swap if there is enough ram and too much swap is in use

    Library: Scripting et automatisme

    #!/bin/bash
    
    totalm=$(awk '/^MemAvailable:/{print $2}' /proc/meminfo)
    swapfree=$(awk '/^SwapFree:/{print $2}' /proc/meminfo)
    SWAP_MAX_USAGE=100000
    RAM_MIN_AVAIL=8000000
    echo "RAM dispo : $totalm vs $RAM_MIN_AVAIL"
    echo "SWAP dispo : $swapfree vs $SWAP_MAX_USAGE"
    
    if [ "$SWAP_MAX_USAGE" -gt "$swapfree" ]; then
      echo "Trop d'usage du swap"
      if [ "$totalm" -gt "$RAM_MIN_AVAIL" ]; then
            echo "Nettoyage cache"
            swapoff -a
            swapon -a
      else
            echo "Pas assez de RAM pour nettoyage cache"
      fi
    fi
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.