LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 04-20-2012, 09:58 AM   #1
ankitpandey
Member
 
Registered: Jan 2012
Location: Mumbai
Posts: 63

Rep: Reputation: Disabled
Disk Space alert


Hello,

I want to enable monitoring on space size, if it exceeds certain limit then it should send alert mail. Please help me with this. Environment is Solaris. I found one code from the forum but that is throwing error (test.sh: syntax error at line 9: `percentuse=$' unexpected) to me


Code:
#!/bin/bash

(

unset FILLING

while read outstring;
do
  percentuse=$(echo $outstring | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $outstring | awk '{ print $2 }' )
  mountedon=$(echo $outstring | awk '{ print $3 }' )

  if [[ $percentuse -ge 90 ]]; then
    FILLING=1
    echo "Filesystem near fill-up : $mountedon"
  fi
done < <(df -Ph | awk '{ print $5 " " $1 " " $6 }')

if [ -z "$FILLING" ]; then
    echo "All filesystem are in safe condition"
fi

) | mail -s "Daily disk space report" me@gmail.com

Last edited by ankitpandey; 04-21-2012 at 02:41 AM.
 
Old 04-20-2012, 11:22 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Please use CODE tags not QUOTE tags around code to make it easier to read. Most easily done by going into Advanced mode and using the # button.

Your code runs OK using bash version 4.1.10, df (GNU coreutils) 8.15 and GNU Awk 3.1.8. What are your versions?
 
Old 04-20-2012, 12:05 PM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,792

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
what is /bin/bash in your environment? bash should understand this

Last edited by pan64; 04-20-2012 at 02:49 PM. Reason: mistyped
 
Old 04-20-2012, 02:46 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by pan64 View Post
what is /usr/bash in your environment? bash should understand this
You mean /usr/bin/bash or /bin/bash, no?
 
Old 04-20-2012, 02:48 PM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,792

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
Quote:
Originally Posted by catkin View Post
You mean /usr/bin/bash or /bin/bash, no?
of course /bin/bash, which is the first line of the script.
 
Old 04-20-2012, 03:09 PM   #6
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 683

Rep: Reputation: 63
I seem to remember a thread a while back asking something similar and pulled this from it:

Code:
for i in `df -h | grep -v capaci | awk '{print $5}' | cut -d% -f1` ; do if [ $i -lt 90 ]; then echo "good" ; else echo "we have a problem on `df -h | grep $i `" ; fi ; done
sample output:
Code:
good
good
good
good
good
good
good
good
good
good
good
we have a problem on /dev/dsk/c0t0d0s6      9.8G   8.8G   994M    91%    /var
good
good
good
good
 
1 members found this post helpful.
Old 04-20-2012, 03:11 PM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Here is your script slightly modified to run on Solaris:

Code:
#!/bin/bash

(
  PATH=$(getconf PATH)
  unset FILLING
  while read outstring
  do
    percentuse=$(echo $outstring | awk '{ print $1}' | cut -d'%' -f1 )
    mountedon=$(echo $outstring | awk '{ print $3 }' )
    if [[ $percentuse -ge 90 ]]; then
      FILLING=1
      echo "Filesystem near fill-up : $mountedon"
    fi
  done < <(df -Ph | awk '{ print $5 " " $1 " " $6 }')
  if [ -z "$FILLING" ]; then
    echo "All filesystem are in safe condition"
  fi
) | mailx -s "Daily disk space report" me@gmail.com
@ankitpandey: as already asked, please edit your first posting and replace the quote tags but code ones.

Last edited by jlliagre; 04-20-2012 at 03:15 PM.
 
Old 04-21-2012, 09:25 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,792

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
Quote:
Originally Posted by Blinker_Fluid View Post
I seem to remember a thread a while back asking something similar and pulled this from it:

Code:
for i in `df -h | grep -v capaci | awk '{print $5}' | cut -d% -f1` ; do if [ $i -lt 90 ]; then echo "good" ; else echo "we have a problem on `df -h | grep $i `" ; fi ; done
this oneliner is a nightmare, an example how one should not do it..
try this, it is almost the same (just won't print "good", and "we have a problem on")
Code:
df -h |awk 'BEGIN { FS="[ %]*"} ($5+0) > 90 { print $NF } '
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script for disk space alert cmontr Programming 6 02-09-2019 04:05 AM
OPENNMS -how can i get disk space alert & memory alert BY MAIL saravanakumar Linux - Server 11 05-30-2014 08:45 AM
[SOLVED] Strange error for disk space alert email script Vi_rod Linux - Newbie 7 12-16-2011 06:09 AM
Disk space alert rbalaa Linux - Software 7 09-05-2011 02:04 AM
LXer: Perl script to monitor disk space and send an email alert LXer Syndicated Linux News 1 02-23-2007 01:12 PM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 06:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration