Output Redirection - Trying to output to screen and file?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Output Redirection - Trying to output to screen and file?
Hi All,
I was hoping to be able to redirect output of a script to the screen and a file as well. I'd like to redirect 2>&1 so stdout and stderr to the screen and also to a file/pipe.
As follows i thought the following would work but it only seems to put stdout to screen and stderr to file/pipe...
Now this is sending data to my central log server that is all working ok, but i'd like both stderr and stdout to be sent to the screen and also to the 'logger' command. I don't think 'tee' is the thing for me (maybe i'm wrong) but its no good because i can't send data to /dev/pts/2 and such because the script isn't going to be running as root either.
Don't think you need to be running as root - this worked for me:
Code:
~$ echo some output | tee /dev/pts/7 | cat > output-file.txt
some output
~$ cat output-file.txt
some output
~$
thanks for the reply but that doesn't work.... i think i may have actually meant something like /dev/stderr OR /dev/fd/[0 OR 1 OR 2 OR 3] they are the stdin stdout and stderr files as such(I THINK?!? not that you can call them files as such either)
I have no /dev/pts/7 for one, and that also won't pick up on stderr output.
Thanks for all help provided from this.. i've looked through the other post as well. Testing of it looks to be working i'll give it a go now and i'll post how i get on.
Code:
command.sh 2>&1 | tee $tty | /bin/logger ....
OK - just run the test
We're almost there... all the data is getting to the mysql database OK which is great. But i'm seeing nothing go to the screen (tty)?
Cheers,
M
Last edited by helptonewbie; 03-18-2009 at 08:13 AM.
Ok to approach this from another angle what could perhaps get this:-
command.sh 2>&1 | tee `/bin/logger ....`
To me the output would be sent to the command 'logger' and also to the shell. But I know 'tee' won't work sending to a command?
The only way i can see that working would be to create a 'fifo' and then get tee to send output to that and have logger attached to that fifo... but this seems stupidly long to do something which is surly simple?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.