Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2006
    Posts
    4

    Unanswered: awk command not working in shell script

    I am trying to grab output from awk utility in a script and email the output but script is failing. On HP 11 platform, I trying to get the fifth field from "bdf /var" output and send myself an email if /var is 90% or more full but I have not been able to get it right. Here is what I wrote:

    #!/bin/sh
    bdf /var |awk '{print $5}'|sed s/%// | awk '{if ($1 >= 90) mail "MyId@email.com"}'
    exit

    And bdf output is like this:
    Server> bdf
    Filesystem kbytes used avail %used Mounted on
    /dev/vg00/lvol7 4194304 1756256 2422400 42% /var

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Wink


    Try this:
    Code:
    #!/bin/sh
    bdf /var |sed 's/%//'|awk '{if ($5 >= 90) print $0;}'|mailx -s"`hostname` -File system full" MyId@email.com
    exit

    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Oct 2006
    Posts
    4
    LKB
    Your code works but it just sends the output from the first line which happens to be the header info, instead of disk utilization Info. Thanks

  4. #4
    Join Date
    Oct 2006
    Posts
    4
    Thanks for everyone's input. This is how it was rewritten and resolved:

    #!/usr/bin/sh
    typeset -i SIZE=$(bdf /var| awk '{getline; sub(/%/,""); print $5;}')
    if [[ $SIZE -gt 50 ]]
    then
    mailx -m -s "[$(date +%m\/%d\/%y)] $rescon /var at 50+%!"MyId@email.com
    fi
    exit 0

Posting Permissions

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