Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Unix Disk usage script

Avatar of miswhoi
miswhoi asked on
Shell Scripting
10 Comments1 Solution1446 ViewsLast Modified:
I'm a little new to scripting.  I'm trying to setup a script that will look atht the filesystem on a sun box and if the disks are at 90% capacity it will fire off an email.

I've been toying around with df -h and awk and I've been reading examples online and trying to make them work but the syntax isn't hitting right on the sun box.

here's an example:
ADMIN="me@somewher.com"
# set alert level 90% is default
ALERT=90
df -H | grep -vE '^Filesystem|tmpfs|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 $ALERT ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space $usep" $ADMIN
  fi


If I try to run grep -vE, the sun box doesn't like it.  I'm decent at programming although it has been a number of years, I've got a decent idea of how to go about this but the syntax is killing me!!
ASKER CERTIFIED SOLUTION
Avatar of simon3270
simon3270Flag of United Kingdom of Great Britain and Northern Ireland image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answers