Awk Problem - Fixing needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk Problem - Fixing needed
# 1  
Old 08-03-2012
Awk Problem - Fixing needed

os: sunos/linux
shell: bash

Code:
                        awk -v PCT="$PERCENTAGE" -v UWARN="$UWARNING" -v UCRIT="$UCRITICAL" 'BEGIN {
                                PCT=PCT+0; UWARN=UWARN+0; UCRIT=UCRIT+0 ;
                                if(PCT<UWARN) { printf \" '${FILESYS}': size('${SIZE}'),usage('${USAGE}'),pct('$PERCENTAGE')\" } }'

i'm getting errors like:

Code:
awk: cmd. line:2:                         	if(PCT<UWARN) { printf \" Virtual
awk: cmd. line:2:                         	                       ^ backslash not last character on line
awk: cmd. line:2:                         	if(PCT<UWARN) { printf \" Memory
awk: cmd. line:2:                         	                       ^ backslash not last character on line

yes i already tried without the back slash and without the "printf". i tried "print". but still not working.
# 2  
Old 08-03-2012
That is a thick mix of awk and shell. I can't even tell what you're trying to do. It almost looks like you're trying to get it to print shell statements, but that's seldom a good idea -- why not do that in the shell itself?

Please tell us what exactly you're trying to do, not just post inscrutable code which can't.
# 3  
Old 08-03-2012
Quote:
Originally Posted by Corona688
That is a thick mix of awk and shell. I can't even tell what you're trying to do. It almost looks like you're trying to get it to print shell statements, but that's seldom a good idea -- why not do that in the shell itself?

Please tell us what exactly you're trying to do, not just post inscrutable code which can't.
Code:
if(PCT<UWARN)

i would have used shell but shell does not handle mathematical equations that involve decimals or negative numbers...which is why i'm using awk.

this seems like an easy fix because all i want to do is just print variables. but this is driving me crazy.

the value inside $FILESYS is usually one word (without any spaces) but some times it can be two words. i.e. "Physical Memory" or "Virtual Memory" or "/var" or "/boot".
# 4  
Old 08-04-2012
It still isn't clear what you're trying to do. You're importing $PERCENTAGE, $UWARNING, and $UCRITICAL; but you're not importing $FILESYS or $USAGE and you're not showing that they are being set in your awk script???

Making lots of wild guesses, would the following be close to what you're trying to do?
Code:
awk -v PCT="$PERCENTAGE" -v UWARN="$UWARNING" -v UCRIT="$UCRITICAL" \
    -v FILESYS="$FILESYS" -v USAGE="$USAGE" \
'BEGIN {PCT=PCT+0;
            UWARN=UWARN+0;
            UCRIT=UCRIT+0;
            if(PCT<UWARN) {
                printf "%s: size(%s),usage(%s),pct(%f)",FILESYS,SIZE,USAGE,PCT}
        }

This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help fixing awk code

can someone please help me spot and fix the issue with the following code: awk -F, -v SEARCHPATT="(Wed|Tue)" -v ADDISTR="Mon|Tue|Wed|Thu|Fri|Sat|Sun" -vVF="$VALFOUND" "BEGIN{ {D = D = 1 D = D = 2 } $0 ~ "," VF "," {L = 1 ... (9 Replies)
Discussion started by: SkySmart
9 Replies

2. AIX

Fixing security problem

Hi I use Rapid 7 to check some servers ( AIX 5.3 ) for security problems. There are 2 problems I don't know to deal with 1. Problem : TCP Sequence Number Approximation Vulnerability Solution : _Enable TCP MD5 Signature 2. Problem : HTTP Basic Authentication Enable Solution : _ Use... (5 Replies)
Discussion started by: bobochacha29
5 Replies

3. Solaris

help needed for fixing zfs bug

Hi Experts I've problem in a my office server (solaris 10 - x86) version. x4600 M2 hardware This system is getting rebooted because of zfs bug I've applied patch using live upgrade with live new environment created and applied the patch which oracle suggested( 144501-19), it asks for... (3 Replies)
Discussion started by: SunSolars_admin
3 Replies

4. Shell Programming and Scripting

help fixing awk statement

awk "BEGIN {if($MessageREAD<$ThresholdW) {print \"OK\" ; exit 0} else if(($MessageREAD>=$ThresholdW) && ($MessageREAD<$ThresholdC)) {print \"WARNING\" ; exit 1}" else if($MessageREAD<=$ThresholdC) {print \"CRITICAL\" ;... (4 Replies)
Discussion started by: SkySmart
4 Replies

5. Shell Programming and Scripting

Help fixing awk code to print values from 2 files

Hi everyone, Please help on this: I have file1: <file title="Title 1 and 2"> <report> <title>Title 1</title> <number>No. 1234</number> <address>Address 1</address> <date>October 07, 2009</date> <description>Some text</description> </report> ... (6 Replies)
Discussion started by: Ophiuchus
6 Replies

6. Red Hat

Help needed in fixing port issue - Urgent

Hi, One of our web application is running in Linux and using apache web servers. Application is hosted in port 4080 (for soap requests) and port 9999, and its serving behind a vip and cname. Initially it was working fine in another server and recently (2 months back) we have moved to the new... (4 Replies)
Discussion started by: senor.ram
4 Replies

7. IP Networking

Specific routing problem help needed

Hi, I am trying to set up the following : - One linux box connected to the net, static address, eth0 - No other eth interface on the box I want to set up this box in a way it can accept remote connections, like pptp tunnels (which seems the easier to set up unless you have other idea)... (2 Replies)
Discussion started by: aerostar700
2 Replies

8. Linux

fixing with sed

I am trying to replace the value of $f3 but its not working . I don't know what I am missing here . cat dim_copy.20080516.sql | grep -i "create view" | grep -v OPSDM002 | while read f1 f2 f3 f4 f5 f6 f7 f8 f9 do echo " $f3 " sed -e... (13 Replies)
Discussion started by: capri_drm
13 Replies

9. Shell Programming and Scripting

eval problem.. advice needed!

Hi I need some major help with eval I have a statement using eval: read input eval variable$input=”something” Now I want to use the “variable$input” in some commands but I don't know how to call it without replacing the $input with the command line value (which I obviously can't do). ... (1 Reply)
Discussion started by: Cactus Jack
1 Replies

10. Solaris

Problem fixing e1000gx ni to 100fdx / Solaris 10 / T5220

Hello ! i'm facing an anoying problem during configuration of our new T5220 Enperise server. I've upgarded 'em with a pci-e ethernet expantion card for four additional networkinterfaces using the nxge drivers. i could fix them to 100 fdx rather simple by adding the following settings to the ... (6 Replies)
Discussion started by: moofoo
6 Replies
Login or Register to Ask a Question