Skip to Main Content

Infrastructure Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Shell Script for sending email on Disk Space Full

RamarajuApr 22 2016 — edited Apr 23 2016

Hi all,

I am getting following exception while executing shell script:

Error:

# sh Diskspace.sh

/dev/mapper/vg_magwebprd-lv_root

Diskspace.sh: line 7: [: /dev/mapper/vg_magwebprd-lv_root: integer expression expected

/ 182G

Diskspace.sh: line 7: [: /: integer expression expected

0% tmpfs

21% /dev/sda1

bs-web:/usr/local/scripts

Diskspace.sh: line 7: [: bs-web:/usr/local/scripts: integer expression expected

/usr/local/scripts 206G

Diskspace.sh: line 7: [: /usr/local/scripts: integer expression expected

bs-web:/usr/local/data/prd

Diskspace.sh: line 7: [: bs-web:/usr/local/data/prd: integer expression expected

/usr/local/data 206G

Diskspace.sh: line 7: [: /usr/local/data: integer expression expected

bs-web:/usr/local/data/refresh

Diskspace.sh: line 7: [: bs-web:/usr/local/data/refresh: integer expression expected

/usr/local/refresh 206G

Diskspace.sh: line 7: [: /usr/local/refresh: integer expression expected

6% tmpfs

Shell Script:

#!/bin/sh

df -H | grep -vE '^Filesystem|cdrom' | awk '{ print $5 " " $1 }' | while read output;

do

  echo $output

  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )

  partition=$(echo $output | awk '{ print $2 }' )

  if [ $usep -ge 91 ]; then

    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |

     mail -s "Alert: Almost out of disk space $usep%" myname@company.com

  fi

done

df -h:

# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/vg_magwebprd-lv_root

                      169G   69G   92G  43% /

tmpfs                 7.8G     0  7.8G   0% /dev/shm

/dev/sda1             477M   92M  361M  21% /boot

bs-web:/usr/local/scripts

                      192G  166G   18G  91% /usr/local/scripts

bs-web:/usr/local/data/prd

                      192G  166G   18G  91% /usr/local/data

bs-web:/usr/local/data/refresh

                      192G  166G   18G  91% /usr/local/refresh

tmpfs                 2.0G  112M  1.9G   6% /ramdisk

Could you please help on this.

Thanks,

Ramaraju

This post has been answered by Dude! on Apr 23 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 21 2016
Added on Apr 22 2016
2 comments
1,055 views