PROJET AUTOBLOG


Shaarli - Nono's Links

Site original : Shaarli - Nono's Links

⇐ retour index

Snippet: Watch free space in shell script (not bash)

jeudi 10 mars 2022 à 13:47
J'ai dû faire un script en shell (et non bash) et j'ai eu quelques adaptation à faire.
Du coup, je publie ici, au cas ou ca intéresse quelqu'un :

------
#!/bin/sh

threshold=90

df -h | awk '{ print $6 " " $5 " " $4 }' |
{
        while read output
        do
                fs=$(echo $output | awk '{ print $1}')
                capacity=$(echo $output | awk '{ print $2}')
                free=$(echo $output | awk '{ print $3}')
                #echo "$fs is used at $capacity ($free left)"
                capa=`echo $capacity | sed 's/.$//'`
                if [ $capa -gt $threshold ]; then
                        issue=true
                        result="$result $fs is used more than $threshold % ($free left)\n"
                fi
        done

        if [ $issue ]
        then
                # somthing wrong
        fi
}
------
Permalink