If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > awk command not working in shell script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-05-06, 09:09
rustic rustic is offline
Registered User
 
Join Date: Oct 2006
Posts: 4
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
Reply With Quote
  #2 (permalink)  
Old 12-05-06, 09:38
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
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
Reply With Quote
  #3 (permalink)  
Old 12-05-06, 10:08
rustic rustic is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 12-05-06, 11:09
rustic rustic is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On