HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
cancel
Showing results for 
Search instead for 
Did you mean: 

Script debug output

 
sa2009
Occasional Advisor

Script debug output

Hello,

I have a script which generates error. I need to capture the output or the error in a debug mode using set -x. How to capture the error in a file in debug mode using set -x

Thanks & Regards
7 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: Script debug output

Hi:

Simply redirect STDERR to your file:

# sh -x ./myscript 2>mytrace

Regards!

...JRF...
sa2009
Occasional Advisor

Re: Script debug output

Hello,

Thanks for your reply. The script is called by some real time application and there is some issue with it. So we want to trace the script using set -x and capture the output in temporary file.

Please suggest.

Regards
James R. Ferguson
Acclaimed Contributor

Re: Script debug output

Hi (again):

> The script is called by some real time application and there is some issue with it. So we want to trace the script using set -x and capture the output in temporary file.

The at the top of the script add the two lines shown below ('exec' and 'set'):

# cat ./thescript
#!/usr/bin/sh
exec 2>/var/tmp/errlog.$$
set -x
...

Your script will write it's trace to '/var/tmp/errlog' with the PID of the process appended for multiple runs or instances.

Regards!

...JRF...
sa2009
Occasional Advisor

Re: Script debug output

will it be stderr(2) or the stdout(1) that will give the relevant data.. please confirm.

Also, do we have to type in "set +x" at the end of the script.
James R. Ferguson
Acclaimed Contributor

Re: Script debug output

Hi (again):

> will it be stderr(2) or the stdout(1) that will give the relevant data.. please confirm.

As I showed, if you want to capture the trace in a file, you need to redirect STDERR to that file.

> Also, do we have to type in "set +x" at the end of the script.

No, when your script exits, the setting ceases to matter. If you only want some particular section of your code traced, then you can bound it by 'set -x' and 'set +x' accordingly.

Regards!

...JRF...
sa2009
Occasional Advisor

Re: Script debug output

Thank You James. I appreciate your assistance in this issue.
James R. Ferguson
Acclaimed Contributor

Re: Script debug output

Hi (again):

> Thank You James. I appreciate your assistance in this issue.

If you are satistied with the answers you have received, please read:

http://forums.itrc.hp.com/service/forums/helptips.do?#28

Assigning points is both a way of saying "thank you" and a way of showing future readers of your thread what helped you solve your problem.

Regards!

...JRF...