Questions tagged [tee]

For questions related to Linux syscall and a user program that duplicates the contents of a pipe. For security frameworks, use the tags [trusted-execution-environment] or [op-tee].

Introduction

The tee command reads from standard input and writes to standard output and files.

Examples of writing standard output include:

# print output of ps to a file
$ ps aux | tee ps_aux.txt

Using tee with sudo command

$ echo 'foo' >> file 
zsh: permission denied: file

As part of a pipe, tee can take the input and elevate permissions

$ echo "foo" | sudo tee -a file 

Links

How do I “tee” variable number of times in a bash “for loop”?

Linux and Unix tee command

536 questions
0
votes
3 answers

Broken pipes and tee?

The output of this echo is not passed on to the next command using pipe. echo 'set foreign_key_checks = 0; truncate table saurabh.bus_services;' | mysqldump --compact --no-create-info -h192.168.950.180 -uroot -p live pnlbus | more I want the set…
shantanuo
  • 31,689
  • 78
  • 245
  • 403
0
votes
1 answer

tee didn't put the output into the file

I was trying to use php file to run a test and get the result. The content in PHP is shown as follows:

Result of…

Charlie Zeng
  • 131
  • 1
  • 3
  • 17
0
votes
1 answer

stdoutt and stderr redirection using tee in shell script

I'm trying to print output/error to console and log file using below code. fun1(){ echo "inside fun1" fun2 var=5 } fun2(){ echo "inside fun2" } fun1 2>&1 | tee -a testlog.txt echo $var # printing null value Any way to print value of var as 5 after…
Anand Tomi
  • 181
  • 1
  • 1
  • 4
0
votes
1 answer

Redirect script output and at the same time display it in realtime

I've got a probably simple (and probably even already answered) question regarding displaying output from several scripts and at the same time writing their stout/stderr to a log file: I have a script "my_script.sh" which itself calls another…
hitme
  • 51
  • 2
-1
votes
1 answer

On what occasion does 'tee' deletes the file it was writing on?

bash4.2, centos the script #!/bin/bash LOG_FILE=$homedir/logs/result.log exec 3>&1 exec > >(tee -a ${LOG_FILE}) 2>&1 echo end_shell_number=10 for script in `seq -f "%02g_*.sh" 0 $end_shell_number`; do if ! bash $homedir/$script; then …
Lunartist
  • 394
  • 1
  • 3
  • 9
-1
votes
1 answer

How to use os.system() to run `> >(tee -a log)`?

I run the following command in the terminal. sh -c "echo out; echo err 2>&1" >>(tee -a stdout.log) 2>>(tee -a stdout.log >&2) output: out err Using os.system in Python will report an error. import os cmd = """ sh -c "echo out; echo err 2>&1" >…
zcfh
  • 101
  • 1
  • 9
-1
votes
1 answer

How to redirect bash stderr to terminal, but also redirect stderr with stdout to log file?

I have a script that QA Manager runs. I want him to take a look at terminal from time to time to take a note if any errors appear. The problem is that the script have a ton of output that we do not need to see. What I am trying to implement: stderr…
Dzmitry Dranitski
  • 165
  • 1
  • 4
  • 13
-1
votes
1 answer

Linux - ffmpeg 3.4.6 vs. 4.2.1 - bash script with Tee (record & stream) runs in older version just fine - what needs to change for new version?

Thanks for reading my post. I have a bash script that I tested and it ran just fine; although I was putting the script into identical hardware as the test computer, I forgot that the target computer would have a newer version of ffmpeg. It should be…
-1
votes
1 answer

Using tee with bash hangs with some scripts

I have a simple script file startsql.sh to start mysql: #!/bin/bash #Script to Start MySQL echo "Starting MySQL" if sudo service mysqld start; then echo "MySQL started successfully!" else echo "Error: Failure to start MySQL" 1>&2 exit…
-1
votes
2 answers

command to redirect output to console and to a file at the same time works fine in bash. But how do i make it work in korn shell(ksh)

command to redirect output to console and to a file at the same time works fine in bash. But how do i make it work in korn shell(ksh). All my scripts runs on korn shell so cant change them to bash for this particular command to work. exec > >(tee -a…
-1
votes
1 answer

Pipe output with tee & grep into file but seeing full output

Trying to get the output of a grep written into a file while having the by grep non-affected output in terminal. Example: command: cat file | grep 'aaa' >> any.txt #Missing parameters here desired output in terminal: aaa bbb ccc redirected into…
Ja Bush
  • 13
  • 4
-1
votes
1 answer

crontab tee command doesn't write stdout into txt file, instead clears it [python script]

I have a crontab command for a python script that prints out files matching certain criteria in a directory. the script prints out the files in a for loop. I then pipe that command to tee the stdout to a file in another directory, and then remove…
-1
votes
2 answers

Ignore tee in linux script

I have a .sh script on a red hat machine: { statement 1 statement 2 statement 3 etc.... } 2>&1 | tee "logdir/logfile.log" which logs both to the console and into logfile logfile.com. However, statement 2 is giving a lot of output and I wish to…
Freeze
  • 237
  • 1
  • 5
  • 12
-1
votes
1 answer

Can't empty many files at once with tee command

I tried three ways of emptying many files at once with the tee command, but nothing is working. What can be going wrong? [root@APPSERVER11-S1 ~]# cat /dev/null | tee /etc/vinter/logs/* [root@APPSERVER11-S1 ~]# ls -l /etc/vinter/logs/* -rw-r--r-- 1…
JM Calil
  • 9
  • 5
-1
votes
3 answers

Best way to get number of lines from command whilst still outputting to both Terminal and to file

I'm currently writing a simple Bash script which finds lines in files which match the target string and outputs this both to the Terminal display but also to a file. The command at the moment is: grep -r -n -F "myname" /Users/tom/Desktop/* | tee…
Tom
  • 159
  • 1
  • 7
1 2 3
35
36