redirect to both file and std output at the same time


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users redirect to both file and std output at the same time
# 1  
Old 09-23-2008
Power redirect to both file and std output at the same time

hello

can some one please help me to redirect the output of a command to both std output and a file. this is little urgent.

sridhar
# 2  
Old 09-23-2008
Use the 'tee' command:
Code:
/usr/bin/generate_stdout | tee -a /filename/to/append/sdtout/to.txt | ./my_command

# 3  
Old 09-23-2008
I'm not sure which unix you are using, but if you have the 'tee' command installed, you can use that.

Code:
# echo hello | tee outfile
hello

Code:
# cat outfile
hello

you can use the -a option to just append to the file

Code:
# echo world | tee -a outfile

and now you have

Code:
# cat outfile
hello
world

If you dont have tee, and cant install it, then you are probably looking at some crazy file descriptor re-assignment/redirection, of which i'm not entirely keen.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirect script output to a file and mail the output

Hi Guys, I want to redirect the output of 3 scripts to a file and then mail the output of those three scripts. I used below but it is not working: OFILE=/home/home1/report1 echo "report1 details" > $OFILE =/home/home1/1.sh > $OFILE echo... (7 Replies)
Discussion started by: Vivekit82
7 Replies

2. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

3. Shell Programming and Scripting

redirect time command output to file (cygwin bash)

I have set up a bash script to run a long list of things that I need to time. I would like to redirect the output of time to a file. I have set it up like, echo "Runtimes for servlet 4, 100K structures" > test_times.txt echo "" >> test_times.txt echo "runs where N=10" >> test_times.txt echo... (7 Replies)
Discussion started by: LMHmedchem
7 Replies

4. AIX

Redirecting Both to a file and std output

Hello Friends, Can some one help me how to redirect output of a file to both a file and std output? All the help would be greatly appreciated. Regards Sridhar (1 Reply)
Discussion started by: send2sridhar
1 Replies

5. Programming

Sun Studio C++ - Getting error in linking std::ostream &std::ostream::operator<<(std:

Hello all Im using CC: Sun C++ 5.6 2004/07/15 and using the -library=stlport4 when linkning im getting The fallowing error : Undefined first referenced symbol in file std::ostream &std::ostream::operator<<(std::ios_base&(*)(std::ios_base&))... (0 Replies)
Discussion started by: umen
0 Replies

6. Shell Programming and Scripting

Real time log file redirect

Hi all, i would like to write the shell script program, it can monitor the access_log "real time" when the access_log writing the line contain "abcdef" the program will be "COPY" this line into a file named "abcdef.txt", do the same thing if the contain "123456" "COPY" it into a file named... (3 Replies)
Discussion started by: eric_wong_ch
3 Replies

7. Shell Programming and Scripting

How to redirect std err and out to log file for multi-commands?

The following command does not work under cygwin bash. ant debug >log 2>&1 && ant image >>log 2>>&1 & pid=$! It gives the error "-bash: sysntax error near unexpected token '&'". Is there a way I can redirect std output and std error to file "log" for both the commands "ant debug" and "ant... (1 Reply)
Discussion started by: siegfried
1 Replies

8. Shell Programming and Scripting

How to redirect std out and std err to same file

Hi I want both standard output and standard error of my command cmd to go to the same file log.txt. please let me know the best commandline to do this. Thanks (2 Replies)
Discussion started by: 0ktalmagik
2 Replies

9. UNIX for Dummies Questions & Answers

Redirect the Time result to a test file

I need to store process runtime into a file, currently the command i use was: time ls >> abc.txt however, this command store the executed result of ls into the txt file but not the time command result. Anyone know how to store the "time ls" result? Please advise me! Thanks in advance :) (5 Replies)
Discussion started by: mistella
5 Replies

10. UNIX for Dummies Questions & Answers

Redirect time output

Hello All, I am trying to write a script that would capture the output of time command on a Sun machine. I have tried these commands $ time ls > out $ time ls 2> out I just get the ls output in the out file for the first one. Thanks for any help Chuck (2 Replies)
Discussion started by: cbeech
2 Replies
Login or Register to Ask a Question