Si je puis me permettre d’ajouter un script un poil plus “complexe” (je ne garantis pas qu’il soit exempt d’erreur, mais il fonctionne pour moi)
[code]#!/bin/bash
#----------------------------------------------------------------------------------------------------------------------------------
usage : checkdiskspace.sh [volume name] [percentage]
Simple bash script : check volume utilization percentage and send mail to root if alert value is reached
can be used in a cron job
requirements : the “mail” command.
default values
volume="/"
percentalert=“90”
show usage with --help
if [ “$1” = “–help” ]; then
echo "Usage: basename $0
[volume name] [percentage]"
exit 1
fi
check volume name
if [ -n “$1” ]; then
# if not null
volume="$1"
fi
check percentage value
if [ -n “$2” ]; then
# if not null
if [ “$2” -ge 0 ] && [ “$2” -le 100 ]; then
percentalert="$2"
else
echo "Invalid percentage value! Must be between 0 and 100…"
exit 1
fi
fi
get occupied percentage for $volume
notice the --max-count in the grep, we only want the first found line
percent=df -x tmpfs -x devtmpfs |grep --max-count=1 " $volume" |awk '{print $5}'|cut -d'%' -f1
if [ -z $percent ]; then
echo "Invalid volume name “$volume”! Volume name must appear in the ‘df’ command’s output."
exit 1
fi
debug
echo “Volume $volume is $percent% used”
if [ $percent -ge $percentalert ]; then
# debug
# echo “alert!“
echo "date
- System uname -n
notice : volume $volume is $percent% full!” |mail -s "uname -n
: disk space alert” root
fi
debug
#echo "date
- System uname -n
notice : volume $volume is $percent% full!" |mail -s "uname -n
: disk space alert" root
exit 0
#----------------------------------------------------------------------------------------------------------------------------------
[/code]