LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-11-2008, 05:28 AM   #1
Kristijan
Member
 
Registered: Sep 2003
Location: Melbourne, Australia
Distribution: NetBSD 3.0.1, Slackware 10.1
Posts: 394

Rep: Reputation: 30
Bash Scripting: Redirect output of entire script to file & screen


Hi All,

Trying to get my head around this one.

How would I redirect stdout and stderr of an entire bash script to a file, but also leaving the output to the screen?

I've tried various combination of exec and tee, and I can't get anything to work =/

Any help is much appreciated.

-Kristijan
 
Old 09-11-2008, 05:31 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
First copy stderr to stdout, then use tee to copy stdout to a file:
Code:
script.sh 2>&1 |tee out.log
 
Old 10-12-2017, 02:38 PM   #3
Mr. Macintosh
Member
 
Registered: Sep 2015
Distribution: Debian, Ubuntu
Posts: 202

Rep: Reputation: 50
Quote:
Originally Posted by matthewg42 View Post
First copy stderr to stdout, then use tee to copy stdout to a file:
Code:
script.sh 2>&1 |tee out.log
Does this work when you're invoking it directly at the CLI or can it be used in a script?
 
Old 10-12-2017, 03:17 PM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,274

Rep: Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994
Just try it, you'll find out.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH: How to Redirect Output to File, AND Still Have it on Screen edwin11 Linux - Software 26 10-12-2017 02:27 PM
Shell scripting: How to redirect output from within the script itself? Arodef Linux - General 4 05-23-2006 07:30 PM
redirect screen output to file timbuck Linux - Software 5 12-09-2005 06:57 PM
Is there a way in Linux/Unix bash to turn off output or redirect to a file jimwelc Linux - Newbie 6 01-06-2005 03:56 AM
Can I redirect script output to a file without ">> $LOGFILE" at the end of each line davee Linux - General 1 12-19-2003 05:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration