943,793 Members | Top Members by Rank

Ad:
Jun 17th, 2009
0

Converting percentage to a number

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shawnk is offline Offline
7 posts
since Jun 2009
Jun 17th, 2009
0

Re: Converting percentage to a number

Click to Expand / Collapse  Quote originally posted by shawnk ...
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.
Reputation Points: 51
Solved Threads: 35
Posting Whiz in Training
Fest3er is offline Offline
238 posts
since Aug 2007
Jun 17th, 2009
0

Re: Converting percentage to a number

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."
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shawnk is offline Offline
7 posts
since Jun 2009
Jun 18th, 2009
0

Re: Converting percentage to a number

Click to Expand / Collapse  Quote originally posted by shawnk ...
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.
Reputation Points: 51
Solved Threads: 35
Posting Whiz in Training
Fest3er is offline Offline
238 posts
since Aug 2007
Jun 19th, 2009
0

Re: Converting percentage to a number

Click to Expand / Collapse  Quote originally posted by Fest3er ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shawnk is offline Offline
7 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Korn shell hangs
Next Thread in Shell Scripting Forum Timeline: Simple script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC