Why Does this Shell Script Hang?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Why Does this Shell Script Hang?
# 1  
Old 11-12-2009
Why Does this Shell Script Hang?

I have this short and simple shell script that processes a log file with the following format:

[function address in hex notation] [timestamp when it was invoked]

and attempts to generate output in the following format:

[function name] [timestamp when it was invoked]

I've come up with the following, but for some reason, it only prints output correctly for the first line of the input file, then hangs indefinitely:

Code:
#!/bin/bash 

for line in $(egrep -o "(0x[0-9a-fA-F]+)\s[0-9]+\.[0-9]+" ./syntax_check_out.txt)
    do 
        addr=`echo $line | egrep -o "0x[0-9a-fA-F]+"` 
        stamp=`echo $line | egrep -o "[0-9]+\.[0-9]+"`
        func=`addr2line -f -e ../mzscheme3m $addr | head -1`
     
        echo "${func} ${stamp}"        
done

Any ideas why this isn't working? I'm not very good with shell scripting, so I may have made an obvious mistake.

Thanks all in advance!

Last edited by Franklin52; 11-12-2009 at 02:11 PM.. Reason: Please use code tags!
# 2  
Old 11-12-2009
Can you post a sample of your input file and the desired output?
# 3  
Old 11-12-2009
I notice the loop construction you chose will put one word per line instead of two. So the assignments inside the loop will not be performed corrrectly. Perhaps this will give a better result (not tested)?
Code:
egrep -o "(0x[0-9a-fA-F]+)\s[0-9]+\.[0-9]+" ./syntax_check_out.txt| 
while read addr stamp; do
  echo "$(addr2line -f -e ../mzscheme3m $addr | head -1) $stamp"
done


Last edited by Scrutinizer; 11-12-2009 at 03:24 PM..
# 4  
Old 11-12-2009
Sample input file attached.

An input line will look like this:

0x49d205 1.265053

And an output line should look like this:

some_function_name 1.265053

I realize I could probably use a sed/awk script for this also, but I don't see any reason why the script I have won't work.
# 5  
Old 11-12-2009
Quote:
Originally Posted by Zoetermeer
Sample input file attached.

An input line will look like this:

0x49d205 1.265053

And an output line should look like this:

some_function_name 1.265053

I realize I could probably use a sed/awk script for this also, but I don't see any reason why the script I have won't work.
Hi,
if the input is consistent, I gues You could simplify Your script a bit, here's a version based on Scrutinizers example:

Code:
while read addr stamp; do
  echo "$(addr2line -f -e ../mzscheme3m $addr | head -1) $stamp"
done <syntax_check_out.txt

And if something goes wrong it's probably in addr2line, what happens if You type

Code:
addr2line -f -e ../mzscheme3m 0x49d205

on the command line?

/Lakris

PS Clarifcation; Is the program ../mzscheme3m available, is it debug-able, etc

Last edited by Lakris; 11-12-2009 at 04:04 PM..
# 6  
Old 11-13-2009
addr2line works fine if I invoke it directly in the shell for any given function address. The binary I'm inspecting is a program I wrote and compiled, and it's fully debuggable.

What a strange problem.
# 7  
Old 11-13-2009
So did you try the revised loop as well? What result did that have?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to solve hang issue in script?

i have one function block in the beginning of my script and there are some commands inside that function which will perform some operations. And i am invoking that function from my main script by passing some values. Sometimes it is hanging in the middle for some value. For example: For 1st... (3 Replies)
Discussion started by: thomasraj87
3 Replies

2. Shell Programming and Scripting

Hang NFS shell script check

Hello all, i wrote a shell script that was running perfectly fine until we had some issue with our NFS server and the script was hung. This script runs every 20 mins and obviously as we had the NFS issue, the script start to hang. as i do a check to make sure NFS directory is avaiable or not.... (7 Replies)
Discussion started by: crazy_max
7 Replies

3. Solaris

ALOM hang

Hi guys, I'm new with solaris. I just received sunfire T2000 server. Problem: ALOM keep hang/stuck/jammed. Steps do before it hang : 1. Connect to T2000 (using RJ45 - DB9 cable) 2. Open putty, connect via serial. 3. Power on the server. 4. Its loading. 5. then, hang. ... (1 Reply)
Discussion started by: rajasraf
1 Replies

4. IP Networking

netstat -a hang

Hi, on our Solaris 10 servers, one day 'netstat -a' command return very slow after TCP output, wait 5 minute on this line - SCTP: Local Address Remote Address Swind Send-Q Rwind Recv-Q StrsI/O State ------------------------------- ------------------------------- ------ ------ ------ ------... (6 Replies)
Discussion started by: ora_dba
6 Replies

5. Shell Programming and Scripting

Script to Kill process which is in hang state

Hi, Can anyone help to create a script that will kill the process which is in hang state. (1 Reply)
Discussion started by: A.Santhosh
1 Replies

6. Shell Programming and Scripting

how do i avoid system hang due to ssh in script?

I have a script that collects data from about 200 servers using 'ssh'. The problem is that, process sometime hangs at some point stopping the execution of the script. Please give me some idea how can I force the execution to jump to the next step if there arises any problem !! Thanks for replies if... (1 Reply)
Discussion started by: mdangol
1 Replies

7. Shell Programming and Scripting

Hang in linux

Hi guys sorry for my English I am from GREECE and I speak from translator.I have in my school work to hang the program I've done is this encounter the problems is that the meter that I have put on the mistakes does not work (I have not stated anywhere lathi = 0, not to reset the meter at each of... (1 Reply)
Discussion started by: soula
1 Replies

8. AIX

Boot from CD hang

Why is one of my blade hanging and does nothing after trying to boot from CD??? ================== I tried to press 1....JS20 does not support SMS menu Here's what I see after 30 minutes... ------------------------------------------------------------------------------- ... (0 Replies)
Discussion started by: mifch
0 Replies

9. Red Hat

system hang

Hello, I am having a HP proliant 350 G3 sever installed wih RedHat linux 9.0 when I enterd using any user(Except root) the server hanged after few seconds, also the folder icons are blacked out and the names of the folder icons are disapper. can any body help me. Ajay (1 Reply)
Discussion started by: ajay234
1 Replies

10. SuSE

Hang a Process

this may be something trivial to many of you, but is there a way to purposely cause a process to hang? (6 Replies)
Discussion started by: laila63
6 Replies
Login or Register to Ask a Question