LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-04-2005, 04:19 PM   #1
jimwelc
Member
 
Registered: Nov 2004
Location: Boston
Posts: 30

Rep: Reputation: 15
Is there a way in Linux/Unix bash to turn off output or redirect to a file


Hello,

I am currently writting a bash script in which I would like to have the ability to run in a silent mode. I come from the windows world and I was hoping there was something like echo ON/echo OFF type command.

Along with this option I would to log everything that was supposed to go to standard out to go to a file. I tried to use the commands "script filename" and "tee filename" but they don't seem to work correctly.

Any help anyone can provide will be greatly appreciated.


Thank you,

-Jim
 
Old 01-04-2005, 04:22 PM   #2
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Rep: Reputation: 52
If you want to run a script and direct output to a file it's:

./script_name > scriptlog.txt

If you run a script and wish to append output to a file it's:

.,/script_name >> scriptlog.txt

-twantrd
 
Old 01-04-2005, 04:28 PM   #3
__J
Senior Member
 
Registered: Dec 2004
Distribution: Slackware, ROCK
Posts: 1,973

Rep: Reputation: 46
redirect it to /dev/null
 
Old 01-05-2005, 12:28 AM   #4
racer_mec
LQ Newbie
 
Registered: Dec 2004
Posts: 11

Rep: Reputation: 0
after the command give the redirect to any file.
like ls > null
this will direct the output of ls to a file named null.
 
Old 01-05-2005, 01:41 AM   #5
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
Here's how you do it from the script itself.
"echo off" style:
Code:
#!/bin/bash

# redirect stdout(1) and stderr(2) to null:
exec 1>/dev/null 2>/dev/null

...the remainder of your script...
logfile style:
Code:
#!/bin/bash

# redirect stdout(1) and stderr(2) to logfile:
exec 1>/path/to/logfile 2>&1

...the remainder of your script...
Yves.

Last edited by theYinYeti; 01-05-2005 at 01:43 AM.
 
Old 01-05-2005, 01:51 PM   #6
jimwelc
Member
 
Registered: Nov 2004
Location: Boston
Posts: 30

Original Poster
Rep: Reputation: 15
Question RE: Is there a way in Linux/Unix bash to turn off output or redirect to a file

Hello all,

I really appreciate everyones responses to my inquire. I think Yves is the route I am going to take, but I was wondering if there is a way to redirect stdout and stderr to screen as well as a file?

Best Regards,
-Jim
 
Old 01-06-2005, 03:56 AM   #7
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
In theory (but I did not try):
Code:
#!/bin/bash

# redirect stdout(1) and stderr(2) to logfile and stdout:
exec 1> >(tee /path/to/logfile) 2>&1

...the remainder of your script...
Yves.
 
  


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
how to redirect the soundcard output to a file? jr0 Linux - General 2 10-31-2005 06:29 AM
How do I redirect sound card output to file ass0ciate Linux - Software 0 09-14-2004 03:41 PM
How to redirect standard output of piped command to log file andrewstr Linux - General 10 02-04-2004 02:07 PM
output from cpio won't redirect to file rawii Programming 5 01-27-2004 01:49 PM
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 > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:09 AM.

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
Open Source Consulting | Domain Registration