Skip to content

Instantly share code, notes, and snippets.

@anjilinux
Forked from tedheich/DiskCheck.sh
Created June 11, 2024 09:27
Show Gist options
  • Select an option

  • Save anjilinux/78468ece4df5eeffc9d30a0c7c5a2688 to your computer and use it in GitHub Desktop.

Select an option

Save anjilinux/78468ece4df5eeffc9d30a0c7c5a2688 to your computer and use it in GitHub Desktop.

Revisions

  1. @tedheich tedheich revised this gist Oct 26, 2009. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion DiskCheck.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ADMIN="yourmail@example.com"
    ADMIN="adminEmail@yourDomain.com"
    # set alert-level 90 % standard
    ALERT=10
    df -h | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
    2 changes: 1 addition & 1 deletion SimplerDiskCheck.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
    THRESHOLD=90

    if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
    mail -s 'Disk Space Alert' mailid@domainname.com << EOF
    mail -s 'Disk Space Alert' sysadmin@yourdomain.com << EOF
    Your root partition remaining free space is critically low. Used: $CURRENT%
    EOF
    fi
  2. @tedheich tedheich created this gist Oct 26, 2009.
    12 changes: 12 additions & 0 deletions DiskCheck.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    ADMIN="[email protected]"
    # set alert-level 90 % standard
    ALERT=10
    df -h | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
    do
    usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
    partition=$(echo $output | awk '{ print $2 }' )
    if [ $usep -ge $ALERT ]; then
    echo "space low on \"$partition ($usep%)\", on server $(hostname) at $(date)" |
    mail -s "Alert: Free space low, $usep % used on $partition" $ADMIN
    fi
    done
    9 changes: 9 additions & 0 deletions SimplerDiskCheck.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    #!/bin/bash
    CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
    THRESHOLD=90

    if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
    mail -s 'Disk Space Alert' [email protected] << EOF
    Your root partition remaining free space is critically low. Used: $CURRENT%
    EOF
    fi