tee

bash: redirect (and append) stdout and stderr to file and terminal and get proper exit status

牧云@^-^@ 提交于 2019-11-29 21:21:30
To redirect (and append) stdout and stderr to a file, while also displaying it on the terminal, I do this: command 2>&1 | tee -a file.txt However, is there another way to do this such that I get an accurate value for the exit status? That is, if I test $? , I want to see the exit status of command , not the exit status of tee . I know that I can use ${PIPESTATUS[0]} here instead of $? , but I am looking for another solution that would not involve having to check PIPESTATUS . Perhaps you could put the exit value from PIPESTATUS into $? command 2>&1 | tee -a file.txt ; ( exit ${PIPESTATUS} )

Tee does not show output or write to file

拟墨画扇 提交于 2019-11-28 23:16:41
I wrote a python script to monitor the statuses of some network resources, an infinite pinger if you will. It pings the same 3 nodes forever until it receives a keyboard interrupt. I tried using tee to redirect the output of the program to a file, but it does not work: λ sudo ./pingster.py 15:43:33 node1 SUCESS | node2 SUCESS | node3 SUCESS 15:43:35 node1 SUCESS | node2 SUCESS | node3 SUCESS 15:43:36 node1 SUCESS | node2 SUCESS | node3 SUCESS 15:43:37 node1 SUCESS | node2 SUCESS | node3 SUCESS 15:43:38 node1 SUCESS | node2 SUCESS | node3 SUCESS ^CTraceback (most recent call last): File ".

How can I gzip standard in to a file and also print standard in to standard out?

跟風遠走 提交于 2019-11-28 20:14:18
I want to execute a command, have the output of that command get gzip'd on the fly, and also echo/tee out the output of that command. i.e., something like: echo "hey hey, we're the monkees" | gzip --stdout > my_log.gz Except when the line executes, I want to see this on standard out: hey hey, we're the monkees echo "hey hey, we're the monkees" | tee /dev/tty | gzip --stdout > my_log.gz As pointed out in the comments, /dev/stdout might work better than /dev/tty in some circumstances. Another way (assuming a shell like bash or zsh ): echo "hey hey, we're the monkees" | tee >(gzip --stdout > my

bash: redirect (and append) stdout and stderr to file and terminal and get proper exit status

谁说胖子不能爱 提交于 2019-11-28 18:47:40
问题 To redirect (and append) stdout and stderr to a file, while also displaying it on the terminal, I do this: command 2>&1 | tee -a file.txt However, is there another way to do this such that I get an accurate value for the exit status? That is, if I test $? , I want to see the exit status of command , not the exit status of tee . I know that I can use ${PIPESTATUS[0]} here instead of $? , but I am looking for another solution that would not involve having to check PIPESTATUS . 回答1: Perhaps you

Pipe output to two different commands [duplicate]

♀尐吖头ヾ 提交于 2019-11-28 17:34:40
Possible Duplicate: osx/linux: pipes into two processes? Is there a way to pipe the output from one command into the input of two other commands, running them simultaneously? Something like this: $ echo 'test' |(cat) |(cat) test test The reason I want to do this is that I have a program which receives an FM radio signal from a USB SDR device, and outputs the audio as raw PCM data (like a .wav file but with no header.) Since the signal is not music but POCSAG pager data, I need to pipe it to a decoder program to recover the pager text. However I also want to listen to the signal so I know

Piping command output to tee but also save exit code of command [duplicate]

心已入冬 提交于 2019-11-28 15:29:27
This question already has an answer here: Pipe output and capture exit status in Bash 15 answers I have a shell script in which I wrap a command (mvn clean install), to redirect the output to a logfile. #!/bin/bash ... mvn clean install $@ | tee $logfile echo $? # Does not show the return code of mvn clean install Now if mvn clean install fails with an error, I want my wrapper shell script also fail with that error. But since I'm piping all the output to tee, I cannot access the return code of mvn clean install , so when I access $? afterwards, it's always 0 (since tee successes). I tried

Misbehaving head with redirection

ε祈祈猫儿з 提交于 2019-11-28 03:34:01
问题 In a reply to Piping a file through tail and head via tee, a strange behaviour of head has been observed in the following construct when working with huge files: #! /bin/bash for i in {1..1000000} ; do echo $i ; done > /tmp/n ( tee >(sed -n '1,3p' >&3 ) < /tmp/n | tail -n2 ) 3>&1 # Correct echo '#' ( tee >(tac | tail -n3 | tac >&3 ) < /tmp/n | tail -n2 ) 3>&1 # Correct echo '#' ( tee >(head -n3 >&3 ) < /tmp/n | tail -n2 ) 3>&1 # Not correct!? Output: 1 2 3 999999 1000000 # 1 2 3 999999

Get exit code from subshell through the pipes

只愿长相守 提交于 2019-11-27 22:16:15
How can I get exit code of wget from the subshell process? So, main problem is that $? is equal 0. Where can $?=8 be founded? $> OUT=$( wget -q "http://budueba.com/net" | tee -a "file.txt" ); echo "$?" 0 It works without tee , actually. $> OUT=$( wget -q "http://budueba.com/net" ); echo "$?" 8 But ${PIPESTATUS} array (I'm not sure it's related to that case) also does not contain that value. $> OUT=$( wget -q "http://budueba.com/net" | tee -a "file.txt" ); echo "${PIPESTATUS[1]}" $> OUT=$( wget -q "http://budueba.com/net" | tee -a "file.txt" ); echo "${PIPESTATUS[0]}" 0 $> OUT=$( wget -q "http:

Piping an interactive session to a file

巧了我就是萌 提交于 2019-11-27 20:50:05
I have made a toy interactive console program that is basically an interpreter: $ myprogram > this is user input this is program output I want to pipe the full session, both user input and program output, into a log file. I can do this like so: $ cat | tee >(myprogram | tee -a file.log) >> file.log > this is user input this is program output $ cat file.log > this is user input this is program output So the above session will display to the terminal as usual but will also be duplicated to the log file. Is there a better way to do this? I don't like how I have to write the log file twice, nor

Use tee (or equivalent) but limit max file size or rotate to new file

空扰寡人 提交于 2019-11-27 19:07:17
I would like to capture output from a UNIX process but limit max file size and/or rotate to a new file. I have seen logrotate, but it does not work real-time. As I understand, it is a "clean-up" job that runs in parallel. What is the right solution? I guess I will write a tiny script to do it, but I was hoping there was a simple way with existing text tools. Imagine: my_program | tee --max-bytes 100000 log/my_program_log Would give... Always writing latest log file as: log/my_program_log Then, as it fills... renamed to log/my_program_log000001 and start a new log/my_program_log. use split: my