LinuxQuestions.org
Review your favorite Linux distribution.
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
 
LinkBack Search this Thread
Old 09-16-2007, 07:11 AM   #1
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 517

Rep: Reputation: 39
Question IS it possible to send command output to a file as well as the screen


Hello people,
I've got a program here and i know how to send stderr and stdout to a log file etc, etc, and of course i know if you don't specify a file those outputs will just be shown in the console window, but is it possible to do both at the same time on the same command, so i can see stderr and stdout as normal on the screen but it can also be getting stored at the same time in a log file. I don't know if something like the [ option1 || option2 ] type of thing comes into the equation by meaning option1 AND option2??

Would be cool if this is possible!! and how?
Cheers
 
Old 09-16-2007, 07:24 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 11,812

Rep: Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923
Have a look at "man tee".
 
Old 09-16-2007, 09:02 AM   #3
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 517

Original Poster
Rep: Reputation: 39
thanks, i've looked at it, but can't get it to workit only prints out stdout i'm using..

bash filename | tee -a log

i looked at the ibm site and they have a method of doing it but it seems complicated for something that should be simple. Thanks for the push in direction
 
Old 09-16-2007, 09:16 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,372

Rep: Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911
Quote:
Originally Posted by helptonewbie View Post
thanks, i've looked at it, but can't get it to workit only prints out stdout i'm using..
Do you mean you get an empty log? Maybe, your script send messages to stderr only. You can try
Code:
bash filename 2>&1 | tee -a log
 
Old 09-16-2007, 10:29 AM   #5
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 517

Original Poster
Rep: Reputation: 39
Thanks, its alwasy the way i did try

bash filename | tee -a log 2>&1

before bothering to post here, should have tried that way to lol, thanks perfect!!!
 
Old 09-16-2007, 12:11 PM   #6
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 517

Original Poster
Rep: Reputation: 39
Ahh not so good, i did try it on a little test and thought it would work fine within my program but it doesn't as i guess the way i invoke the commands are a little different.

what i have is a file with a lot of different commands in that can be executed. this works as follows.

PATH=$PATH:/path_to_commandfile
commandfile [argument]

then in the command file is a function and therefore depending on what argument was passed depends on the commands that are run within that file, what i would like to do is get the stdout and stderr onto the output on the screen, so basically where ever commandfile [argument] is run, it already outputs fine to a log file, but i can't see it on the screen even with the tee command i guess because its not sending the output to the right tty or something?? any ideas
 
Old 09-16-2007, 01:13 PM   #7
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 517

Original Poster
Rep: Reputation: 39
Its ok all sorted now, thanks to people for their help

Final Result:-
run on screen
screen_pts=`tty`
echo "screen_pts="$screen_pts > file1


run in command file
source file1
command 2>&1 | tee -a log >> $screen_pts

works like a charm
Cheers
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
send output of namp scan to CSV file rsmccain Linux - Networking 11 04-18-2009 08:31 PM
Send ALL output streams to file? Nuvious Linux - General 1 04-22-2007 02:08 PM
redirect screen output to file timbuck Linux - Software 5 12-09-2005 06:57 PM
Can not send cron output to the screen tryingHarder Linux - Newbie 3 09-26-2004 10:11 PM
Log Screen Output to a file sdandeker Linux - Newbie 3 09-17-2003 02:57 AM


All times are GMT -5. The time now is 02:32 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration