Find the answer to your Linux question:
Results 1 to 5 of 5
Hi All, I wrote a small script, which finds the size of "/" and "/var" FS, if it exceeds 80% it should alert me. The below is my script. hname=`hostname` ...
  1. #1
    Just Joined!
    Join Date
    Mar 2009
    Posts
    13

    Bash Scritping

    Hi All,

    I wrote a small script, which finds the size of "/" and "/var" FS, if it exceeds 80% it should alert me. The below is my script.

    hname=`hostname`
    FS="/ /var"
    Size="80"
    for i in ${FS[@]}
    do
    Disk_Free=`df -h $i | tail -n 1 | awk '{ print $4 }'`
    if [ $Disk_Free -ge $Size ]
    then
    echo "$i" needs attention in "$hname"
    else
    echo "$i" is OK in "$hname"
    fi
    done


    The problem I am facing is i dont know how to remove the % symbol from df -h output, because of this my script is not working properly. Any help will be appreciated.

    If for example output of the below command is 85%, I want to remove the % symbol from this output in a single command

    Disk_Free=`df -h $i | tail -n 1 | awk '{ print $4 }'`

    Thanks
    Puru

  2. #2
    Linux Newbie Ziplock's Avatar
    Join Date
    Jan 2009
    Location
    Adelaide
    Posts
    169
    Hi Puru,

    Try:

    Disk_Free=`df -h $i | tail -n 1 | sed 's/%//' | awk '{ print $4 }'`

  3. #3
    Just Joined!
    Join Date
    Mar 2009
    Posts
    13
    Quote Originally Posted by Ziplock View Post
    Hi Puru,

    Try:

    Disk_Free=`df -h $i | tail -n 1 | sed 's/%//' | awk '{ print $4 }'`
    @Ziplock,

    Thank You it works fine

  4. #4
    Linux Newbie Ziplock's Avatar
    Join Date
    Jan 2009
    Location
    Adelaide
    Posts
    169
    Happy to help!

  5. #5
    Just Joined!
    Join Date
    Apr 2011
    Posts
    1
    I am doing an assignment for my linux class and this is very similar to what I am doing, but not only do i need to be alerted about a filesystem becoming full, but i need a beep command that would beep along with an alert message. Anyone knows how to add a beep command on a script? I've been checking through various sites and none seems to work so far.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...