The UNIX and Linux Forums  
Hello and Welcome from to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Hanging port? NycUnxer UNIX for Dummies Questions & Answers 1 01-09-2008 02:21 PM
hanging sockets!??! Naanu SUN Solaris 1 02-08-2007 09:15 PM
Hanging commands jOOc UNIX for Dummies Questions & Answers 0 07-05-2006 12:14 PM
how to tell if process is hanging dangral UNIX for Dummies Questions & Answers 2 01-07-2004 08:43 AM
mq_open Hanging Deepa High Level Programming 0 06-24-2003 07:06 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-29-2008
unakon unakon is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 3
Problem with awk hanging

I have a problem with an awk command.

I have a expect script running on one node that is executing a command on another node.
Both nodes are Linux.

The script on the remote node is supposed to check a couple of logs after "type" notifications.
I am using tail and awk to do that.
The env NO_OF_NOT shall step each time a type=1 notification has been found and when 6 are found the script should exit:
-----------------------------------------
NO_OF_NOT=6

# Wait for $NO_OF_TP notifications
echo "Will wait for $NO_OF_TP start-notifications."
echo "Waiting..."

tail -F -n0 ~/consolelogs/start* \
| awk '/type=9/ {print "Servlet not Started Error: "; print} \
/type=5/ {print "Application could not be Started Error: "; print} \
/type=1/ {++n; print; if (n=='$NO_OF_TP') exit}' >& 1 2> /dev/null


echo "All notifications received"
------------------------------------------

The script works fine but it does not do exit when NO_OF_NOT has been reached.
What am I doing wrong?

Kind Regards
/Andreas
  #2 (permalink)  
Old 03-29-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
You call it NO_OF_TP in other places. I don't see you incrementing or using NO_OF_NOT at any point after declaring it.
  #3 (permalink)  
Old 03-29-2008
unakon unakon is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 3
In the awk the variable n is used to increment.
NO_OF_NOT is only used as a constant.
  #4 (permalink)  
Old 03-29-2008
unakon unakon is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 3
Sorry I missed that.
But it still will not work.
It just hangs and will not stop.

-----------------------------------------
NO_OF_NOT=6

# Wait for $NO_OF_NOT notifications
echo "Will wait for $NO_OF_NOT start-notifications."
echo "Waiting..."

tail -F -n0 ~/consolelogs/start* \
| awk 'BEGIN { n = 0 } /type=9/ {print "Servlet not Started Error: "; print} \
/type=5/ {print "Application could not be Started Error: "; print} \
/type=1/ {++n; print; if (n=='$NO_OF_NOT') exit}' >& 1 2> /dev/null


echo "All notifications received"
------------------------------------------
  #5 (permalink)  
Old 03-29-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Are you getting any type=1s then? Make it echo something when it sees one so you see it's getting caught correctly.
  #6 (permalink)  
Old 03-29-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,307
Use a variable in awk:

Code:
tail -F -n0 ~/consolelogs/start* \
| awk -v NON=$NO_OF_NOT 'BEGIN { n = 0 }
/type=9/ {print "Servlet not Started Error: "; print} \
/type=5/ {print "Application could not be Started Error: "; print} \
/type=1/ {++n; print; if (n==NON)exit}' >& 1 2> /dev/null
Regards
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:37 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0