Problem with awk hanging


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with awk hanging
# 1  
Old 03-29-2008
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  
Old 03-29-2008
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  
Old 03-29-2008
In the awk the variable n is used to increment.
NO_OF_NOT is only used as a constant.
# 4  
Old 03-29-2008
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  
Old 03-29-2008
Are you getting any type=1s then? Make it echo something when it sees one so you see it's getting caught correctly.
# 6  
Old 03-29-2008
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
# 7  
Old 03-29-2008
Interpolating the shell variable into the script should work just as well.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sftp hanging

Hi All, I am transfering a file through sftp. But the script is hanging at exit occasionally. I am suspecting that sftp is hanging due to buffer size issue. If that is the case can any body suggest a solution. Please find the code. echo "cd /${CUST_ID}/inbound/${SAFET_ID}" >... (0 Replies)
Discussion started by: Girish19
0 Replies

2. UNIX for Dummies Questions & Answers

netstat -a is hanging??

Hi, I am on Solaris 10 server. I wanted to see a port is ESTABLISHED or in the LISTEN mode. But when I do netstat -a |grep 22205, it's hanging. I have waited over two minutes. Is it possible, something else is wrong on the server? I don't see anything on /var/adm/messages file. ... (3 Replies)
Discussion started by: samnyc
3 Replies

3. Shell Programming and Scripting

awk hanging from running command

awk -v youth=1599 -v d="$(/bin/ps -ef)" 'd ~/ 1599 / && d !~/ awk / && (($2 == youth) || ($3 == youth)) {print $2" "$3}' i feel like i'm very close here. what am i doing wrong? (1 Reply)
Discussion started by: SkySmart
1 Replies

4. Shell Programming and Scripting

nslookup hanging

Hey folks. Long time lurker, first time poster. I'm a bit of a newbie at "coding" (obviously, scripting is a teensy bit different than coding) and I've run into a problem that I just can't seem to get around. I'm going through a list of servers to check their name, IP, reverse-NSLOOKUP name and... (2 Replies)
Discussion started by: Bearwhale
2 Replies

5. Solaris

df command hanging

Hi Folks, When i execute the command df -kh in my system the o/p hangs.. The command runs fine but takes a lot of time before coming back to the # prompt. Can anyone please suggest the possible cause and solution?. (10 Replies)
Discussion started by: vivek.goel.piet
10 Replies

6. Solaris

Mailx hanging problem

Hi all, I issued the following mailx -s "TEST" <mail> However it just hang there. :wall: How do i diagnose why it behave like this? Thanks. ---------- Post updated at 02:20 PM ---------- Previous update was at 10:27 AM ---------- No reply on this. Any help will be appreciated. I'm... (2 Replies)
Discussion started by: beginningDBA
2 Replies

7. Shell Programming and Scripting

Script is hanging

Hello, I have the following shell script and when i execute, it keeps hanging and nothing happens Please let me know. Requirement is to read data from file and pass it to the sql and create files as shown. code /******** #!/bin/sh while read user.dat do echo "user = $1 email =... (1 Reply)
Discussion started by: rakeshsr12
1 Replies

8. UNIX for Dummies Questions & Answers

ps command is hanging

Hi All, I am unable to figure out why my ps command is haning. Is some one else is running a process which is hanged. But in that case also if i do ps it should show only the processes running by me only. Thanks & Regards Gauri Agrawal (2 Replies)
Discussion started by: gauri
2 Replies

9. UNIX for Dummies Questions & Answers

how to tell if process is hanging

On Solaris 8.. 28166 user 3693M 2736M sleep 5 0 0:05.38 0.0% PROCESS/4 How can I tell if this process is doing anything or just hanging? (2 Replies)
Discussion started by: dangral
2 Replies

10. Programming

mq_open Hanging

One of my program which uses posix message queues was hanging in mq_open() system call, and after some time, it threw an error "Interrupted system call". I couldnt even unlink that message queue using mq_unlink(), as I have to use mq_open() prior to mq_unlink(). I use SunOS 5.7 Generic_106541-22... (0 Replies)
Discussion started by: Deepa
0 Replies
Login or Register to Ask a Question