Questions tagged [tee]

tee is a command line utility that reads the standard input and writes to the standard output as well as a file specified as an argument. Use this tag for questions about the tee command.

Filter by
Sorted by
Tagged with
0
votes
1answer
39 views

How to remove noise in speakers?

After my operating system boots, I can hear repeatedly scratch-like noise from speakers. I googled this problem, and almost found solutions somewhere: if I type like a echo 0 | sudo tee /sys/module/...
1
vote
1answer
33 views

What is use case for -p flag in tee

Just reading the man page for tee, it says: -p diagnose errors writing to non pipes I'm just wondering what is the use case for this?
0
votes
0answers
30 views

Bash save results to file .txt [duplicate]

I want to save the result to a file and display the result on the console at the same time. How best to do it find /etc -size -100c | sort | perl -pe 'print ++$c . "\n\n" if $. % 30 == 0'
4
votes
2answers
109 views

Run every bash command through a function, or wrapper

So I want any and every command that I run to be piped to another command, and I tried using a .bashrc function: * () { ${@} | [my command] } So for example, what I really wanted to achieve was ...
0
votes
1answer
31 views

Adding line to sudoers.d with tee not working

I need to make a user able to reload php-fpm. When i run below code to append below line via tee from the root user nothing happens except i enter insert mode (lines with > ) that i can only close ...
3
votes
3answers
107 views

bash: race condition with pipeline, tee and process substitution

I want to see twice being output twice, but this script will only output it once: dump() { (sleep 1; cat) > "$1" } (sleep 0; echo "twice") | tee >(dump "./a.txt") echo "$(< "a.txt")" To ...
0
votes
1answer
28 views

Create a text files from the output of find command and send the text file to a remote server using SFTP

I have a find command that gives the list of files that are older than 5 days, i can tee it into a text file. find . -type f -mtime +5 -ls | tee $dir/new.txt Now i want to send this text file to a ...
2
votes
0answers
26 views

Pipe output to a command while still writing to stdout [duplicate]

I have a command that writes to stdout, let's say it's ls. I want to pipe its output to a program foo, while still writing that output to stdout. I looked into tee, but I couldn't figure out how to ...
1
vote
2answers
21 views

How to sudo copy a file and pass argument to it with shell script

I want to use shell scripts to set up my virtual machine. Example script.sh has pip install wheel pip install cookiecutter pip install flask pip install gunicorn pip install uwsgi Then I want it to ...
2
votes
1answer
90 views

How can i put the gcc warning messages in a text file? [duplicate]

I wished to know if someone knew how to put the compilation warnings of GCC in a text file ? For example : I wrote (willingly) a undefined function foo(). So gcc tell me : warning: implicit ...
0
votes
2answers
129 views

How to print the output of `read -p` to stdout and another file

I was doing echo -n " - This directory is not empty, purge? (Y/N): " | tee -a $mylogs read choice echo "$choice" | tee -a $mylogs but I wanted to try to condense it to: read -p " - This ...
1
vote
3answers
253 views

Is there a standard alternative to sponge to pipe a file into itself?

I frequently want to do something like this: cat file | command > file (which obviously doesn't work). The only solution I've seen for this is sponge, i.e. cat file | command | sponge file ...
0
votes
2answers
136 views

Best way to `tee` to stdout and to a process

I want to do something like this: echo 'foo' | tee /dev/stdout > >(cat) where the stdout from echo gets sent to the terminal and to the cat process. Is there a simpler way to do this? When I ...
1
vote
4answers
90 views

grep file names from a text file and print the name of shell file calling that file into a text

I have some script name along with their path stored in a text file. The text files contains paths like /myhome/new1/myfiles/test2.sh /myhome/new3/myfiles/test1.sh /myhome/new2/myfiles/test4.sh /...
3
votes
3answers
255 views

How to save command as well as output of that command to a file [duplicate]

Hi I want to save both output of a command and the command that has been run to create the output into the same single file. I understand either of *some_command* > file.txt *some_command* | ...
1
vote
0answers
112 views

When piping to a command via tee, output of first command is lost

The following command displays output of only grep command. df|tee >(head -1) |grep -i '/dev' whereas the following command gives output of both grep and head command df|tee >(head -1) >(...
1
vote
1answer
517 views

Script hanging when using tee and wait, why?

I'm running a script which automates snapraid for my NAS server. It's a script I found online and it was working without issue on Debian 9. I updated to Debian 10 last week and the script now hangs in ...
1
vote
1answer
53 views

Can I safely git/commit/push or rsync a file being currently written by tee without breaking any pipe?

I have a pipe working for several days and writing some scientific results at a very low rate (a block of about 20 lines once an hour); most of the time, nothing is written. The file is written by tee....
1
vote
2answers
432 views

How display output command and pipe it to next command? [duplicate]

I would like to dispay the ouput (STDOUT) and also pipe to the next command. I know "tee" to display the result and write to a file, but instead to write to a file, I want to pipe to another command. ...
0
votes
2answers
49 views

Joining a standard output and susbtitution thereof into table

Say I have: $ cat tmp1.txt a b c Then $ paste tmp1.txt <(tr '[:lower:]' '[:upper:]'<tmp1.txt) a A b B c C How would I modify the above to 1/ invoke tmp1.txt only once? (I suspect tee)...
0
votes
0answers
46 views

Script - Write stdout and stderr to a file AND to the terminal without pipe [duplicate]

I don't know if it's possible, I would like start a bash script without pipe which write everything to a file and at the same time see the output on the terminal. So I know how to do that with this ...
1
vote
1answer
52 views

How “some_command | sudo tee” really works?

I guess I know when there is a pipe (|) the left-side command is executed first and the result is passed to the right-side command of pipe but... apt update | sudo tee ... how can work that way? ...
0
votes
3answers
58 views

What is the best way to direct stdout & stderr to multiple logfiles?

I have a purge process that I am running and the command I'm using is : find $sentPurgerFolder -mtime +7 -print -delete >> $sentPurgeLogFile 2>&1 This code is in a while loop that is ...
1
vote
3answers
89 views

Writing to 2 SD cards at the same time

I would like to write an image at two SD cards at the same time. I envision at least two concurrent writing scenarios: Is it possible to write the image with a tee or similar bifurcating mechanism? ...
0
votes
1answer
140 views

Redirecting to both screen and file

I'd like to redirect all of the output of the commands I ran to a file, in addition to having them printed on the screen. I want this to happen automatically, I don't want to pipe into tee everytime ...
0
votes
0answers
23 views

How can I catch command status code and throw error before tee? [duplicate]

I want to catch (and throw error) before tee command. #!/usr/bin/env bash set -xe serverless | tee /tmp/output.txt However serverless command fails, tee returns non-error status code. How can I ...
5
votes
1answer
373 views

Process substitution and redirection using tee

Suppose that you redirect, in bash, the standard output of a command cmd to a file named f.out, and the standard error to f.err, using tee to preserve console printing: cmd 1> >(tee f.out) 2>...
2
votes
1answer
69 views

Combine brace and variable expansion in one line

I would like to have a logging function that takes filenames as arguments and replicate the stdout to all of these files. This is what I have come up so far: function logger() { exec > >(...
3
votes
3answers
455 views

tee into different variables

From the bash code command1 | tee >(command2) | command3 I want to capture the output of command2 in var2 and the output of command3 in var3. command1 is I/O-bound and the other commands are ...
1
vote
1answer
159 views

Inject string in tee output

I am using pipelines to implement some functionality with bash on Centos 6. During these pipes I want to export my data in a log file, but this data comes from different pipes in my pipeline and I ...
2
votes
2answers
259 views

Forward pg_dump to 2 different psql, one log file but not the console

I am trying to push the pg_dump to 2 psql and to a log file but I don't want to add noise to my terminal. Following the numerous post of the tee tool, I reached this command which is indeed working ...
2
votes
1answer
307 views

Redirect script output both to console and to log

Take a look on the following # more /tmp/myscript #!/bin/bash echo I AM echo BIG GUY echo AND ALSO SMART # bash /tmp/myscript | tee -a >/tmp/log why we not get the output from echo in the ...
0
votes
1answer
138 views

Bash output redirection to new file each time command is run

I have a Bash one-liner that redirects the output of a command to a new, fresh file each time the command is run. Logging the output of each time the command is run is important (I'm using ls here as ...
-1
votes
2answers
558 views

Tee does not write to file when combined to pipe

I'm trying to run a C code with matlab, developed by others. In c, it's written to stdout, then in matlab a pipe is created and read: unix('rm -f /tmp/matdata.in;mkfifo /tmp/matdata.in'); unix(['./',...
2
votes
3answers
247 views

tee sends incomplete data

$ head -c10G /dev/zero | tee >(head -c1M | wc -c) >(head -c10M | wc -c) >(head -c100M | wc -c) >(head -c1000M | wc -c) gives: 1048576 1064960 1064960 1064960 I would have expected: ...
1
vote
1answer
192 views

Explanation of unpredictable behaviour of tee

I encountered a behaviour that I don't understand while testing a script that sums the outputs from repeated executions of a program. To reproduce it create the text files out, which represents the ...
1
vote
2answers
2k views

Is there any difference between tee and >> when using echo?

Is there any difference beteween doing: echo "hahaha" >> file1 and echo "hahaha" |tee -a file1 ? Yes, I noticed that I cannot write to write protected files even aith sudo echo, but I can ...
1
vote
3answers
819 views

How to grep from tee?

I want to check wether the output of my command contains "rerun" (and then rerun) but I also want to display the whole output. I know that I could use one of these: command | tee >(grep rerun) ...
-2
votes
1answer
334 views

What is the difference (if any) between “cat input | tee > output” and “tee < input > output”?

I obtained the following: $ time $(tee < infile > outfile) real 0m14.721s user 0m0.094s sys 0m2.629s $ time $(cat infile | tee > outfile) real 0m8.931s user 0m0.123s sys 0m3.168 Is that ...
1
vote
1answer
441 views

Print and log stdout and stderr in fish shell

I am using the fish shell and try to log stdout and stderr into two separate files and printing them in the terminal at the same time (e.g., by piping each stream to tee). In bash I would do (see ...
0
votes
1answer
292 views

Redirecting stdout and stderr when installing software

I would like to be able to simply save stdout and stderr when installing software There are 3 scenarios I would like to address: When using apt-get When using apt-get and tee When using make install ...
1
vote
1answer
63 views

Send stderr to a different receiver in pipe

Right now I have this: echo "$run_test" | bash 2>&1 | prepend "r2g-test:" "yellow"; What this does is prepend "r2g-test:" to each line of the stdout/stderr. Because I am sending stderr to ...
1
vote
1answer
231 views

Send find's output to stdout and piped to grep

I have a 100+ rar files which I want to extract using find's exec command. I'd like to see the usual rar output so I can monitor its progress, and also to pipe the output to grep and then on to wc to ...
1
vote
1answer
640 views

How to output SSH commands that are being sent to a server

I have a script that connect to a Network device. It runs some commands and basically I want to output the SSH commands that are being executed. To make myself clearer, I connect to one device, ...
0
votes
1answer
443 views

overwrite file and echo to stdout

I have a simple bash function to increment a number and store it in a file: get_next_int (){ my_file="$HOME/next_int.json" touch "$my_file" typeset -i my_num=$(cat "$my_file") echo "$((++...
3
votes
2answers
3k views

hide output of command while using cat and tee

I have a text file that contains some IPs. I want to copy the contents of this text file into /etc/ansible/hosts without showing the output on the terminal (as shown in example 2). Note: root user is ...
0
votes
1answer
69 views

response checker in a script

I have following response checker in a script: #!/bin/bash test_fn() { WARNFILE=$1 echo echo "--- BEGIN ---" cat ${WARNFILE} echo "--- END ---" echo while true; do read -r -n 1 -p "Continue? [y/...
0
votes
1answer
640 views

Writing user input to file using tee

I have a script which guides users through the installation of my software and I want to write a log file in case something bad happens and the user needs support. The script looks like this: while ...
1
vote
1answer
427 views

Read stdin and pass through pipeline to tee

I'm playing around with xinput to watch keyboard events. I'd like to transform the output with awk and pass it to tee, printing to stdout and writing to a file simultaneously. I watch events on ...
0
votes
0answers
406 views

scripting with telnet and tee

with #!/bin/bash telnet ipaddr port & i=1 while [ "$i" -lt 3 ] do (( i += 1 )) sleep 10 done result: Trying ipaddr... Connected to ipaddr. Escape character is '^]'. ...