The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
let curl output to stdout AND save to a file scarfake Shell Programming and Scripting 3 05-31-2008 04:16 PM
Save TCL Procedure Output gjsaravanan UNIX for Dummies Questions & Answers 1 11-21-2007 07:00 AM
Man command doesn't display any output amonst other problems djdavies AIX 6 02-02-2007 06:07 AM
Man command doesn't display any output amonst other problems :-) djdavies UNIX for Dummies Questions & Answers 14 02-01-2007 11:42 AM
terminal output - save to file? frustrated1 SUN Solaris 2 11-15-2005 09:19 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-31-2008
satimis satimis is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 45
Command display output on console and simultaneously save the command and its output

Hi folks,


Please advise which command/command line shall I run;

1) to display the command and its output on console
2) simultaneous to save the command and its output on a file


I tried tee command as follows;

$ ps aux | grep mysql | tee /path/to/output.txt

It displayed the command and its output on console but only saved the
output on output.txt without the command executed.


2)
$ ls -l | tee -a /path/to/outpu.txt

The output was added to the file also without the command.


3)
$ locate test.txt | tee -a /path/to/output.txt
locate: warning: database `/var/cache/locate/locatedb' is more than 8
days old

It won't add the warning on the file.


Please help. TIA


B.R.
satimis
  #2 (permalink)  
Old 07-31-2008
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
Quote:
Originally Posted by satimis View Post
3)
$ locate test.txt | tee -a /path/to/output.txt
locate: warning: database `/var/cache/locate/locatedb' is more than 8
days old

It won't add the warning on the file.
to get errors and warnings in the output file, you need to redirect them
Code:
$ locate test.txt 2>&1 | tee -a /path/to/output.txt
  #3 (permalink)  
Old 07-31-2008
satimis satimis is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 45
Quote:
Originally Posted by Yogesh Sawant View Post
to get errors and warnings in the output file, you need to redirect them
Code:
$ locate test.txt 2>&1 | tee -a /path/to/output.txt
Hi Yogesh Sawant,


I got it. Thanks.


Leaving behind is how to save the command together with its output on the file.


B.R.
satimis
  #4 (permalink)  
Old 07-31-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Perhaps the script command would be closer to what you are looking for. Or you can run the shell with tee, something like

Code:
sh -ix <commands.txt 2>&1 | tee -a /path/to/output.txt
You'd put your canned commands in commands.txt (mainly because typing anything into a shell which is running with redirection is not exactly user-friendly).

Last edited by era; 07-31-2008 at 04:25 AM.. Reason: Flags -ix, not sure if you want one or both or something else
  #5 (permalink)  
Old 07-31-2008
satimis satimis is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 45
Quote:
Originally Posted by era View Post
Perhaps the script command would be closer to what you are looking for. Or you can run the shell with tee, something like

Code:
sh -ix <commands.txt 2>&1 | tee -a /path/to/output.txt
You'd put your canned commands in commands.txt (mainly because typing anything into a shell which is running with redirection is not exactly user-friendly).
Hi era,


Thanks for your advice.


What does commands.txt refer to?


e.g. to run "ls -l" command. What will be the complete command line? TIA


B.R.
satimis
  #6 (permalink)  
Old 07-31-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Yeah, something like echo ls -l | sh -ix and if it looks like you want it, add the tee

To my amazement, I found that at least bash in sh mode works pretty well interactively even with the redirection to tee. Maybe you don't have to put your commands in a file after all.
  #7 (permalink)  
Old 07-31-2008
satimis satimis is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 45
Quote:
Originally Posted by era View Post
Yeah, something like echo ls -l | sh -ix and if it looks like you want it, add the tee

To my amazement, I found that at least bash in sh mode works pretty well interactively even with the redirection to tee. Maybe you don't have to put your commands in a file after all.
Hi era,


Noted with thanks.


script command solves my problem.

$ script /path/to/output.txt

$ run other commands

$ exit
save all output including commands on the file.

$ script -a /path/to/output.txt
resume script and continue adding output on the file.


Thanks


B.R.
satimis
Sponsored Links
Closed Thread

Bookmarks

Tags
redirect, script, tee

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 03:12 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0