Converting percentage to a number

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2009
Posts: 5
Reputation: shawnk is an unknown quantity at this point 
Solved Threads: 0
shawnk shawnk is offline Offline
Newbie Poster

Converting percentage to a number

 
0
  #1
Jun 17th, 2009
Hello,

I am trying to use the awk command to print two columns. One of them has a percentage value. This is for file system monitoring. When i try to read it from a file it does not recognize the precent sign and ignores it. How can i convert it or skip the % sign when using this command?

Any help would be appreciated.

Thanks.
Shawn

#! /usr/bin/ksh
HOST=`hostname`
cd /home/orabp1/scripts

/usr/bin/df -g | grep -i /bp1db01_bk|awk '{print $7" "$4}' > fs_usage
if [ `cat fs_usage |awk '{print $2}` -gt 36 ]
then
mailx -s "Backup Filesystem Usage in $HOST has exceded" acvd@drede.com < fs_usage
fi


bckp_chk.sh[7]: 35%: 0403-012 A test command parameter is not valid
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: Converting percentage to a number

 
0
  #2
Jun 17th, 2009
Originally Posted by shawnk View Post
Shell Scripting Syntax (Toggle Plain Text)
  1. ...
  2. /usr/bin/df -g | grep -i /bp1db01_bk|awk '{sub (/%/, "", $7); print $7" "$4}' > fs_usage
  3. ...
Adding a sub() statement to your awk code that deletes the % from the df() output should work. The above syntax should work on your system (AIX & Pains or Solaris?); I'm still using a 1988 version of AT&T's AWK book.

Your code is sub-optimal, but that don't matter because it isn't running 1,000,000 times a second. It'll work.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 5
Reputation: shawnk is an unknown quantity at this point 
Solved Threads: 0
shawnk shawnk is offline Offline
Newbie Poster

Re: Converting percentage to a number

 
0
  #3
Jun 17th, 2009
That worked perfect but now i get this error msg for the next line.
My dumb brain can't figure out how to fix it

if [ `cat fs_usage |awk '{print $2}` -gt 36 ]

I tried to change it and put another quotation mark but it didn't solve the issue.

"0403-012 A test command parameter is not vaild."
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: Converting percentage to a number

 
0
  #4
Jun 18th, 2009
Originally Posted by shawnk View Post
That worked perfect but now i get this error msg for the next line.
My dumb brain can't figure out how to fix it

if [ `cat fs_usage |awk '{print $2}` -gt 36 ]

I tried to change it and put another quotation mark but it didn't solve the issue.

"0403-012 A test command parameter is not vaild."
That's what happens when you've been looking at the problem too long. I'm going through the same thing now on my own project ('updating' Smoothwall Express to use LFS 6.4). Boy am I overlooking stuff that doesn't become obvious very quickly!

Your awk code is missing the closing apostrophe. And you'll probably find $1 has the numeric value to compare.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 5
Reputation: shawnk is an unknown quantity at this point 
Solved Threads: 0
shawnk shawnk is offline Offline
Newbie Poster

Re: Converting percentage to a number

 
0
  #5
Jun 19th, 2009
Originally Posted by Fest3er View Post
That's what happens when you've been looking at the problem too long. I'm going through the same thing now on my own project ('updating' Smoothwall Express to use LFS 6.4). Boy am I overlooking stuff that doesn't become obvious very quickly!

Your awk code is missing the closing apostrophe. And you'll probably find $1 has the numeric value to compare.

Thanks for your help previously.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC