Results 1 to 5 of 5
I want to do the following redirectin inside a bash script :
1. all the stdout will be redirected to a /tmp/log
2. all the errors will go to the ...
- 10-23-2010 #1Just Joined!
- Join Date
- Jan 2008
- Posts
- 28
how to redirect inside bash script, BUT...
I want to do the following redirectin inside a bash script :
1. all the stdout will be redirected to a /tmp/log
2. all the errors will go to the stderr and also to the /tmp/log.
The following inside a bash script is not working, WHY and HOW to do it:
#!/bin/bash
exec 1>/tmp/log
exec 2> > (tee -a /tmp/log)
....
rest of the bash script.
- 10-26-2010 #2Just Joined!
- Join Date
- Jan 2008
- Posts
- 28
Experts on bash Redirections?
Anyone can help on that?
- 10-31-2010 #3
This link might help.
BASH Programming - Introduction HOW-TO: All about redirection
- 10-31-2010 #4Just Joined!
- Join Date
- Jan 2008
- Posts
- 28
Redirection issue
I didn't find the answer to my question in the link(BASH Programming - Introduction HOW-TO: All about redirection).
This link has a basic redirection example, and want I need it a bit complicated redirection issue.
- 10-31-2010 #5Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
I think what you'll have to do is create a child process running tee and use a named pipe to redirect stderr to it. That way stderr will print on the terminal and to the log.
Code:#!/bin/bash npipe=/tmp/$$.tmp trap "rm -f $npipe" EXIT # Delete named pipe on script exit mknod $npipe p # Create the named pipe tee <$npipe -a /tmp/log & # Create child process running tee with stdin redirected to named pipe exec 1>/tmp/log # Redirect stdout to log exec 2>&- # Close stderr exec 2>$npipe # Open stderr on named pipe


Reply With Quote