awk completes early


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk completes early
# 1  
Old 07-30-2007
awk completes early

Hi All.....

I have a text file with a good number of rows, example below. The script is to work out percent of failures. The problem I have is that the script exits after the first result is given. From this example here I should have two output lines, one from GetOffers and ListOffers. Any idea why this may be?

Quote:
(I) Jul 27 09:18:44:900 TIB_TUX_EXC2CCOS_SERVER[ 27527] user1: Service[ListOffers] started
(I) Jul 27 09:19:01:220 TIB_TUX_EXC2CCOS_SERVER[ 27527] user1: service [GetOffers] returns [0]
(I) Jul 27 09:19:28:777 TIB_TUX_EXC2CCOS_SERVER[ 27527] user1 : Service[ListOffers] started
(I) Jul 27 09:19:32:698 TIB_TUX_EXC2CCOS_SERVER[ 27527] user1 : service[ListOffers] returns [-1]
(I) Jul 27 09:19:48:878 TIB_TUX_EXC2CCOS_SERVER[ 27527] user1 : Service[ListOffers] started
(I) Jul 27 09:19:51:316 TIB_TUX_EXC2CCOS_SERVER[ 27527] user1 : service[ListOffers] returns [0]

Code:
percent()
{

awk -- 'BEGIN{EQUATION='"$*"';printf("%0.1f%\n",EQUATION)}'


}

order()
{

echo Start ordering

grep "] started" $file | awk '{print $10}' | sort | uniq | while read line
do

line=${line#\[}
line=${line%]}

started=`grep "] started" $file | grep -c $line`
returns=`grep "returns \[" $file | grep -c $line`
failreturn=`grep "returns \[-1" $file | grep -c $line`

printf "Fail percent on $line = \c"

percent "$failreturn / $returns * 100"

echo $line
#printf "\n"

done

}

while getopts f:ohd name
do
        case $name in
                f)
                        file="$OPTARG";;
                o)
                 order;;
                h)
                 hourly;;
                d)
                 day;;
                *)
                 usage;;
        esac

done

# 2  
Old 07-31-2007
I don't think that $line is being set properly. Try changing...
Code:
grep "] started" $file | awk '{print $10}' | sort | uniq | while read line
do

line=${line#\[}
line=${line%]}

:

to
Code:
awk -F '[\]\[]' '/] started/{print $4}' $file | sort -u | while read line
do

:

# 3  
Old 08-02-2007
Thanks for the reply...I did try the awk method but got only error messages.

I'm still struggling but now get another issue that i can't figure out. I have suplied the full script I have written. The new problem is that when the daily percentage of failures is worked out it doesn't return to the command prompt after giving the percent result. If I check the processes running it still has the percent function running. I can't figure what it is waiting on.



Code:
#set -x

# Usage

usage()
{
echo "
        Usage:check_CCOS_actions -f <file name> -ohd

        Where.....

        o - Failure by order type
        h - Failure by hour
        d - Failure by day
     "
exit 1
}

percent()
{
awk 'BEGIN{EQUATION='"$*"' ;printf("%0.1f%",EQUATION)}'
}

order()
{
echo Start ordering

grep "] started" $file | awk '{print $10}' | sort | uniq | while read line
do

line=${line#\[}
line=${line%]}

started=`grep "] started" $file | grep -c $line`
returns=`grep "returns \[" $file | grep -c $line`
failreturn=`grep "returns \[-1" $file | grep -c $line`

printf "Fail percent on $line = \c"

percent "$failreturn / $returns * 100"
done
}

hourly()
{
echo nothing
}

day()
{

started=`grep -c "] started" $file`
returns=`grep -c "returns \[" $file`
failreturn=`grep -c "returns \[-1" $file`

printf "Fail Percent to date = \c"
percent "$failreturn / $returns * 100"

#exit 0
}

while getopts f:od name
do
        case $name in
                f)
                        file="$OPTARG";;
                o)
                 order;;
                d)
                 day;;
                h)
                 hourly;;
                *)
                 usage;;
        esac

done

if [ "$file" = "" ]
then
        usage
fi

# 4  
Old 08-02-2007
If on Solaris, use nawk.
# 5  
Old 08-03-2007
MySQL

Smilie


Good call, change all awk to nawk and it returns as expected. I do wonder what the difference is Smilie.


Not that it makes any odds.

Cheers and beers,

Neil
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

<< Environmental Variables are not set when script completes >>

Hi Team, I have a wrapper script which i have pasted below, it internally calls one python script to generate Environmental in a file called /home/oracle/myenv.sh, when i execute this script via wrapper script, its not reflecting in my current session, still showing old env variables. any... (2 Replies)
Discussion started by: kamauv234
2 Replies

2. Shell Programming and Scripting

While loop - how to run processes one after another (2nd starts after first completes, and so on)

I'm a programming noob. I'm trying to run a memory intensive process for many files. But when I use the following script, it runs fine for the first 5-7 files, then runs out of memory. Monitoring the output files, it's clear the processes are going on in parallel. Once 5-7 of the files are being... (18 Replies)
Discussion started by: pathunkathunk
18 Replies

3. Shell Programming and Scripting

Read file contents and separate the lines when completes with =

Hi, I have a file like this cpsSystemNotifyTrap='2010/12/14 11:05:31 CST' Manufacturer=IBM ReportingMTMS=n/a ProbNm=26 LparName=n/a FailingEnclosureMTMS=7946-IQL*99G4874 SRC=B3031107 EventText=Problem reported by customer. CallHome=true Calendar I want to have a output like this... (6 Replies)
Discussion started by: dbashyam
6 Replies

4. UNIX Benchmarks

Early PowerMac G5

Hardware Overview: Model Name: Power Mac G5 Model Identifier: PowerMac7,2 Processor Name: PowerPC 970 (2.2) Processor Speed: 1.8 GHz Number Of CPUs: 2 L2 Cache (per CPU): 512 KB Memory: 1.5 GB Bus Speed: 900 MHz Boot ROM Version:... (0 Replies)
Discussion started by: tnorth
0 Replies

5. UNIX for Advanced & Expert Users

how to delay a process getting killed before it completes its work

The problem i am encountering is the process is getting killed before it dispalys the details.The details are displayed using printf.I created a new buffer for printing the details using setvbuf function call instead of output buffer.This is not working.The thing is,killing of the process must be... (1 Reply)
Discussion started by: cijkmysj
1 Replies

6. Shell Programming and Scripting

remove directory x seconds after script completes

Hi guys, I am working with a script within a Mac OS X package installer. The package installer will run the bash script once the files have been copied/installed. I have a little trouble with the last line of my script causing the package installer to crash once in a while and I have narrowed it... (1 Reply)
Discussion started by: tret
1 Replies

7. Shell Programming and Scripting

Append Status to echo'd line after process completes

Hello All, I'm very new to scripting and I'm writing a very simple script to restart a couple processes because I'm getting to lazy to cd between directories. This is pretty much my first script and I just want to add a little cosmetics to it. Here's what I have: #!/bin/ksh echo... (5 Replies)
Discussion started by: Setan
5 Replies
Login or Register to Ask a Question