Inaccurate awk response


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inaccurate awk response
# 1  
Old 03-30-2014
Inaccurate awk response

can someone help me figure out what's wrong with this awk code?

Code:
awk '/CRON/ && /./ {i++;} { if((i>=4) && (i<8)) {print | "TIMO=$(date +%s) ; TIMO2=$(uname;who) ; echo $TIMO ---- 1 ---- Yes_Recoded,$TIMO2 ---- i >> /tmp/gona.txt" }
 else if (i>=8) {print | "TIMO=$(date +%s) ; TIMO2=$(uname;who) ; echo $TIMO ---- 2 ---- Yes_Recoded,$TIMO2 ---- i >> /tmp/gona.txt"} } {i++;} 
END { if(i<4) {print | "TIMO=$(date +%s) ; echo $TIMO ---- 0 ---- No_Recoded ---- i >> /tmp/gona.txt" } }' /var/log/syslog

first of all, it appears two conditions are being met at once as I'm getting responses for both Warning and Critical ( 1 and 2 ).

after each condition is met, i want to see the value of "i". but the output i get is just the letter i, without its value:

Code:
1396193620 ---- 1 ---- Yes_Recoded,Linux jserver tty7 2014-03-28 01:44 (:0) jserver pts/3 2014-03-28 01:44 (:0) jserver pts/4 2014-03-28 01:45 (:0) jserver pts/0 2014-03-28 01:48 (:0) ---- i

# 2  
Old 03-30-2014
A few comments:
- How do you see two conditions are met? There's only one output line in your sample.
- && /./ will be TRUE for any non-empty line, as . matches any char.
- The "i" you refer to is an awk- variable, but your file is written from a (sub-) shell, where "i" is not defined (were it, it needed a $ sign for evaluation). Plus, awk's print is lost - you're not reading stdin anywhere in the shell.
- formatting/indenting the awk- script nicely will make it way more readable and understandable!
# 3  
Old 03-30-2014
Quote:
Originally Posted by RudiC
A few comments:
- How do you see two conditions are met? There's only one output line in your sample.
- && /./ will be TRUE for any non-empty line, as . matches any char.
- The "i" you refer to is an awk- variable, but your file is written from a (sub-) shell, where "i" is not defined (were it, it needed a $ sign for evaluation). Plus, awk's print is lost - you're not reading stdin anywhere in the shell.
- formatting/indenting the awk- script nicely will make it way more readable and understandable!
fixed! it's working now. thank you Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Inaccurate scanning of Bash array elements

username=cogiz #!/bin/bash shuffle() #@ USAGE: shuffle { #@ TODO: add options for multiple or partial decks Deck=$( printf "%s\n" {2,3,4,5,6,7,8,9,T,J,Q,K,A}{H,S,D,C} | awk '## Seed the random number generator BEGIN { srand() } ## Put a random number in front... (4 Replies)
Discussion started by: cogiz
4 Replies

2. Red Hat

Response Times

Hello all. Let me qualify my question by saying that I am struggling with how to ask the question I am semi green but have no issue reading up if pointed in the right direction. Please be gentle! A RHEL server 6.2. Hosts a statistical application that has some web apps and batch programming... (0 Replies)
Discussion started by: rsheikh01
0 Replies

3. Solaris

Inaccurate file size report with du?

This is really strange... my system's du is reporting file size smaller than it really is... and it is only happening on one of Solaris 10 I have... #ls -lrt tracks.txt -rw-r--r-- 1 oracle oinstall 2166525362 May 16 03:32 tracks.txt # du -k tracks.txt 953805 tracks.txt # du -h... (4 Replies)
Discussion started by: JT-KGY
4 Replies

4. Infrastructure Monitoring

SNMP disk space - inaccurate numbers

on the remote server that im running the snmp command against, below is the information about the specific directory i'm concerned about: SIZE USED AVAIL 673G 483G 157G can someone explain to me why snmp is telling me the size of this filesystem is 176399584? ... (5 Replies)
Discussion started by: SkySmart
5 Replies

5. AIX

Ping response

:confused:Hi, In linux if ping to a system from a linux server it shows ping time=0.120ms how we can achive this in aix. i need this for a latency check. Thanks in advance. (5 Replies)
Discussion started by: vjm
5 Replies

6. IP Networking

Traceroute response

I have 20 servers I installed an application to that is returning message " wrong dispatcher or port " when starting agents. They all have the same dispatcher ip and going through the same port number. After verifying there are no application issues, we figured it was firewall related. The Firewall... (1 Reply)
Discussion started by: HFJ
1 Replies

7. UNIX for Dummies Questions & Answers

Automate response to prompt

I'm running a program in the terminal on a computer running ubuntu. After inputing a file containing 900 data sets, I have to enter the line number a particular data set I want to analyze begins on, followed by the number that corresponds to the type of analysis I want. I have to do this for every... (0 Replies)
Discussion started by: red baron
0 Replies

8. UNIX for Dummies Questions & Answers

response of a for loop?!

Dear guys, I don't know the response of a for loop in this situation: suppose that file1 is an empty file. and i make a for loop as : for i in `cat file1` What will be the response of the for loop: 1- will an error message apear 2- or the for loop simply will not run,and it will escape... (2 Replies)
Discussion started by: marwan
2 Replies

9. SCO

Slow cd response

Hi All We have one SCO Server here and it never gives us any trouble. Until Now!! Well its not earth shattering but we have one user who is complaining of a very slow response time when changing to his Home Directory. Other users who have similar profiles are OK. I have su'd to this user and I can... (0 Replies)
Discussion started by: JohnOB
0 Replies
Login or Register to Ask a Question