Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I log output of a shell script and also display on the screen? [duplicate]

I am running a script called upgrade.sh

ANd upgrade.sh calls a script called roll.sh

roll.sh >> logfile.text

But roll.sh has some questions and prompts, and the redirect is preventing those outputs from hitting the screen. I cannot edit roll.sh.

I also tried `results=$(roll.sh)

Even then, the output was not coming onto the screen

like image 597
roymustang86 Avatar asked Feb 15 '13 18:02

roymustang86


2 Answers

Use tee, it was created specifically for this purpose: to forward standard input to the screen and one or more files. Make sure to use the -a option to append to logfile.text if you don't want to overwrite it.

roll.sh | tee -a logfile.text
like image 140
Cory Klein Avatar answered Sep 25 '22 18:09

Cory Klein


You want tee:

TEE(1)                           User Commands                          TEE(1)



NAME
       tee - read from standard input and write to standard output and files
like image 41
evil otto Avatar answered Sep 24 '22 18:09

evil otto