![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
|
||||
|
Quote:
I got it. Thanks. Leaving behind is how to save the command together with its output on the file. B.R. satimis |
|
||||
|
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 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 |
|
||||
|
Quote:
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 |
|
||||
|
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. |
|
||||
|
Quote:
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 | ||
|
|