How to stop debug in the mid of process?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to stop debug in the mid of process?
# 1  
Old 11-06-2013
How to stop debug in the mid of process?

Hi Gurus,

I am debugging a script. it loops filelist. since the list a very long. when debugging, I only can see the last a few lines. is there any way to stop debuger in the mid of process.

the command I used for debugging is:
Code:
ksh -x scriptName

Thanks in advance
# 2  
Old 11-06-2013
Yes, modify the script...
make it read a key ( any.. you dont care its just for stopping...) you enter...
# 3  
Old 11-06-2013
Add the following to the top of your script and execute it normally. Press the ENTER key to step through the script:

Code:
set -x
trap "read" DEBUG

These 3 Users Gave Thanks to in2nix4life For This Post:
# 4  
Old 11-06-2013
Not really with invoking it that way. Perhaps you would be better to capture the output to a file and then view that later on:-
Code:
$ ksh -x scriptName >/tmp/script.log 2>&1

If you need to interact with it, you could do the following:-
Code:
$ touch /tmp/script.log
tail -f /tmp/script.log &
ksh -x scriptName >>/tmp/script.log 2>&1

Note the append to log >> in this case.


I hope that this helps.

Robin
Liverpool/Blackburn
UK
# 5  
Old 11-06-2013
Quote:
Originally Posted by in2nix4life
Add the following to the top of your script and execute it normally. Press the ENTER key to step through the script:

Code:
set -x
trap "read" DEBUG

This way works perfect

Thanks
This User Gave Thanks to ken6503 For This Post:
# 6  
Old 11-06-2013
You can also select the lines in a script that you want to trace. The command:
Code:
set -x

turns tracing on for following commands in the script, and the command:
Code:
set +x

turns tracing off for following commands.
# 7  
Old 11-07-2013
Don has it - as always - right: instead of tracing the script wholesale you should trace one (small) piece after the other. Set pairs of set -xv and set +xv and move these pairs around while debugging.

Another thing is: debugging output happens on <stderr> and you can catch this output and display it pagewise:

Code:
/your/script_with_tracing.sh 2>&1 | more

My favourite is yet to (mostly) skip tracing altogether. In most cases you can put in some diagnostic messages into your script. Suppose you have the following:

Code:
while [ $value != something ] ; do
     command1
     command2
     value=$(some_command giving some value)
     command3
done

Instead of decorating such a loop with "set +/- xv" you could also build in a diagnostic message and let it run:

Code:
while [ $value != something ] ; do
     command1
     command2

     echo "old value is $value"
     value=$(some_command giving some value)
     echo "new value is $value"
    
     command3
done

Now you will get pairs of before- and after-values and can probably find the culprit. Maybe there is another component involved, so output that too with each pass of the loop. You get the idea.

Once you found and corrected the problem you remove these lines again and start working on the next bug the same way.

Another possibility is to display commands instead of executing them. Replace any:

Code:
problematic_command $value1 $value2

with

Code:
DEBUG="echo "       # somewhere at the beginning of execution

...

$DEBUG problematic_command $value1 $value2

You can decorate several interesting commands like that. If you set DEBUG to "echo" they are not executed but displayed like they would be executed, quite similar to what you see with "set -x". Set DEBUG to "" and they are executed normally again. This way you can switch between debugging runs and normal runs easily.

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Question: HowTo Exit Script with User Input While Process is Running Mid-Loop?

Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Discussion started by: hilltop_yodeler
9 Replies

2. Shell Programming and Scripting

How to stop the process in shell scripting?

Hi all, I have tried the below code to execute. #! /bin/bash date1=`date -d "today 08:00:00" +%s` date2=`date -d "today 08:01:00" +%s` path=/home/user01/red/IDC/sample cd $path java Cspsamp 111.19.5.172 7025 rd1 rd1 "5022=Query|5026=109378|4=627|5=E:VD|5042=$date1|5049=$date2"... (5 Replies)
Discussion started by: aish11
5 Replies

3. UNIX for Dummies Questions & Answers

Stop the process

I have the following log file running since yesterday and its consuming so much of the disk space. -rw-rw-r-- 1 dev dba 4543237120 Nov 10 09:00 load_run_file1_0.1111091224.lg How do i kill this process. I don't have any idea of stopping this. Any help would be really appreciated. ... (3 Replies)
Discussion started by: bobby1015
3 Replies

4. Shell Programming and Scripting

Process running? Stop it

I have this "process keepalive" script: #!/bin/bash PIDFILE=/tmp/php.pid PHPSCRIPT=/home/www/mydomain.com/subdomains/www/parser.php echo 'Checking php process from PID file' if ; then PID=`cat $PIDFILE` if ps ax | grep -v grep | grep $PID > /dev/null then echo "php process still... (4 Replies)
Discussion started by: LukasB
4 Replies

5. Shell Programming and Scripting

how to stop the process that is running continously

Hi there, I have written a script to check daily process, each script is in a different directory. Now the first process is running fine, when it goes to the next directory the process doesn't executes. cd result/logs ref=month_1888.log echo $ref>> $logfile cd /max/tot/first... (3 Replies)
Discussion started by: NehaKrish
3 Replies

6. Programming

Debug two process Using GDB

Hi All I know How to attach a process to beubg it .But for my application I am using client as well server.Both are two separate process .Suppose I need to debug both .How to attach both of them together .Or I have to attach them separetly . Suppose client process id is 1325 and server is... (2 Replies)
Discussion started by: mr_deb
2 Replies

7. AIX

a process that never stop

Dears all i have an AIX box in which i am facing a problem with a process as below: /usr/dt/bin/dtexec -open 0 -ttprocid and each time i am killing this process with "kill -9" then it run again after a while. any ideas or solutions will be appreciated. (13 Replies)
Discussion started by: TheEngineer
13 Replies

8. Shell Programming and Scripting

Stop / kill the process individually

Hi , I have a situation, where I have 10 indivudal processess started by similar instance.I say similar instance because each of them being started as a new thread: Say I've following unix process running process1_ADAP process2_ADAP process3_ADAP Current scenario: Now I have SHUTDOWN... (5 Replies)
Discussion started by: braindrain
5 Replies
Login or Register to Ask a Question