- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how do I redirect output for set -x
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 02:08 PM
01-29-2003 02:08 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 02:21 PM
01-29-2003 02:21 PM
Re: how do I redirect output for set -x
Theres a 3rd output stream (called Std-something). Undocumented of course.
"2>&1" does not pick it up, but "|tee -a /tmp/abc" probably will. Try it and see!
Ancient Proverb - "Give a programmer a well-defined set of standards, and they shall find a way to break them!"
Share and Enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 02:22 PM
01-29-2003 02:22 PM
Re: how do I redirect output for set -x
The easiest way is to start a typescript file.
# script /tmp/output
# run_my_script.sh
The output will go to both the screen and the /tmp/output file.
HTH
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 02:25 PM
01-29-2003 02:25 PM
Re: how do I redirect output for set -x
#!/usr/bin/sh
set -x
date
echo hi
echo bye
Now:
./mysh 2> ./mysh.debug.debug
...directs stderr to the .debug file...
...and:
/tmp/tester 2> /tmp/tester.debug 1>&2
...directs both stderr and stdout to the .debug file.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 03:18 PM
01-29-2003 03:18 PM
Re: how do I redirect output for set -x
Not sure if this is you problem but here goes...
In your question you have:
"2>&1 >/tmp/abc"
This will NOT send stderr and stdout to the file /tmp/abc
">/tmp/abc 2>&1" WILL send both stderr and stdout to the file /tmp/abc
Order does matter.
Hope this helps...
Tony
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 04:40 PM
01-29-2003 04:40 PM
Re: how do I redirect output for set -x
I already have a wrapper for my scripts. Essenentially the wrapper does:
daScript |tee -a logfile 2>&1
contents of daScript
set -x
echo abc
echo 123
echo easy as
The trace does not end up in the logfile.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 04:50 PM
01-29-2003 04:50 PM
Re: how do I redirect output for set -x
I have just tested the following script,...
#!/usr/bin/hs
# Comment - wrong shell is deliberate
bdf
# End Script
By running '/tmp/test1 2>&1 |tee -a /tmp/aa' picks up the error in the file /tmp/aa.
By running '/tmp/test1 |tee -a /tmp/aa 2>&1', no output is displayed in the /tmp/aa file.
Running 11.11 (64bit), Patch Dec 2001, on a N4000.
Try reversing the order of 'tee' and '2>&1' as in the first example in this posting.
Share and Enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 04:54 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 05:02 PM
01-29-2003 05:02 PM
Re: how do I redirect output for set -x
Is this what you want?:
The wrapper:
#!/usr/bin/sh
/tmp/tester 2>&1|tee -a /tmp/tester.debug
The script (/tmp/tester):
#!/usr/bin/sh
set -x
date
echo hi
echo bye
exit 0
NOW: The output (stderr & stdout) appear both on your terminal *and* in /tmp/tester.debug:
+ date
Wed Jan 29 20:01:38 EST 2003
+ echo hi
hi
+ echo bye
bye
+ exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 05:11 PM
01-29-2003 05:11 PM
Re: how do I redirect output for set -x
send stderr to stdout as currently defined
and >/tmp/abc says: send stdout to /tmp/abc
but stderr was connected to stdout *before* it was redefined. So stderr goes to whatever stdout used to be.
The correct order is: redirect stdout, then redirect stderr to whatever stdout has become:
sh -x script_name >/tmp/abc 2>&1
I debug scripts this way by piping the stderr and stdout into more as in:
sh -x script_name 2>&1 | more
Note that -x is effective for the main body of the script and disappears inside functions. Also note that stderr (trace output) may not be perfectly shuffled into the stdout lines...shell timing issues.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2003 05:41 PM
01-29-2003 05:41 PM
Re: how do I redirect output for set -x
Richard