- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Too late to redirect stdout/stderr after script is...
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
10-17-2005 05:15 AM
10-17-2005 05:15 AM
myscript 1>/tmp/junk 2>&1
But what I'm trying to do in this case is capture the output from the actual running script itself after it has started. Is this possible? For example:
#!/usr/bin/sh
# Sample script
export STDOUT=/tmp/junk
export STDERR=/tmp/junkerror
echo Hello World
exit
I'm just not sure of the syntax or whether it's even possible.
Thanks in advance,
Tim
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 05:33 AM
10-17-2005 05:33 AM
Re: Too late to redirect stdout/stderr after script is running??
echo "Hello World" 1>/tmp/junk 2>/tmp/junkerror
I believe you would get what your example was trying for.
The tee command may also give you some more options.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 05:36 AM
10-17-2005 05:36 AM
Re: Too late to redirect stdout/stderr after script is running??
I guess I didn't give a very good example. I knew I could redirect the output for that single echo command as you suggested.
Instead of just a single echo command the script actually contains dozens of commands doing a variety of things.
I'm trying to capture all the output from all the commands without individually redirecting all of them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 05:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 05:50 AM
10-17-2005 05:50 AM
Re: Too late to redirect stdout/stderr after script is running??
for it in a for loop (with one pass).
for i in 1
do
mycommand
nextcommand
another command
yet another command
done > myoutputfile 2>&1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 05:51 AM
10-17-2005 05:51 AM
Re: Too late to redirect stdout/stderr after script is running??
exec 1>/tmp/junk.out
exec 2>&1
do other stuff...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 06:13 AM
10-17-2005 06:13 AM
Re: Too late to redirect stdout/stderr after script is running??
You can of course use other programming techniques to simplify the task. If all the scripts that you are calling use the same redirection, try creating a function that takes the scripts as a parameter to the function. Then run that script from the function and apply the redirection there. That way you program it once and use it many times.
Best of luck!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 12:47 PM
10-17-2005 12:47 PM
Re: Too late to redirect stdout/stderr after script is running??
"If no arguments are given, the effect of this command is to modify file descriptors as prescribed by the input/output redirection list."
So, you can redirect stdin, stdout and stderr. So for your example:
exec 1>$STDOUT 2>$STDERR
You can also redirect stderr into stdout:
exec 2>&1
Or any of the redirection features of the shell. There is no limit on using exec multiple times with different redirection options.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 06:55 PM
10-17-2005 06:55 PM
Re: Too late to redirect stdout/stderr after script is running??
exec 2>/tmp/err.log 1>/tmp/output.log
Ways more:
a)
(
echo "ok"; # std output command
ls /stand/muthu; # std error command ;)
) 1> /tmp/out.log 2>/tmp/err.log
b)
{
echo "ok"; # std output command
ls /stand/muthu; # std error command ;)
} 1> /tmp/out.log 2>/tmp/err.log
hth.