LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-26-2012, 05:18 PM   #1
NuUser
LQ Newbie
 
Registered: Mar 2012
Posts: 5

Rep: Reputation: Disabled
logging output at cmdline


Hi, I want to open a logfile.log then execute several cmds at cmdline one at a time. The output should be log to logfile.log. Finally, when finish all the cmds, I want to save/close the logfile.log. My question, can I do this on linux?
 
Old 03-26-2012, 05:20 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
How automated do you want this to be?

Something as simple as appending ">> logfile.log" to each line might do what you need, ie:
Code:
command1 >> logfile.log
command2 >> logfile.log
command3 >> logfile.log
If you want things to be more automated, you could redirect stdio to logfile.log. You could also use "tee" to split output to both the console and the logfile.
 
Old 03-26-2012, 05:22 PM   #3
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
@ Reply

Hi NuUser,

Welcome to LQ!!!

Yes, it is possible and you can do it using script command as follows:

Code:
script -f <filename>
filename will be the name of the file in which you want to save the output. -f option is used to specify the filename. Once you execute this command it will show a message as below:

Quote:
Script started, file is <filename>
Again, filename will be the name you have given with script command above. This command will log everything that will type in the terminal. Remember this is only valid for the terminal you are working on. If you open up another terminal at the same time then it will not be ablicable to that terminal.

I hope this helps.
 
Old 03-26-2012, 05:39 PM   #4
NuUser
LQ Newbie
 
Registered: Mar 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by T3RM1NVT0R View Post
Hi NuUser,

Welcome to LQ!!!

Yes, it is possible and you can do it using script command as follows:

Code:
script -f <filename>
filename will be the name of the file in which you want to save the output. -f option is used to specify the filename. Once you execute this command it will show a message as below:



Again, filename will be the name you have given with script command above. This command will log everything that will type in the terminal. Remember this is only valid for the terminal you are working on. If you open up another terminal at the same time then it will not be ablicable to that terminal.

I hope this helps.
Thank you. But I tried as you mentioned the above script -f modesense.log, then I executed sg_modes ... after that, I vi modesense.log, and I see nothing. Do I have to close the logfile?
 
Old 03-26-2012, 05:45 PM   #5
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
@ Reply

Oops!!! Sorry I forgot to mention that you need to type exit to write to the log file. Once you will type exit it will display a message saying
Quote:
Script done, file is <filename>
 
  


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
Terminal 0.2.6 output logging clonas Linux From Scratch 2 08-29-2008 04:19 AM
Logging a script output ZAMO Linux - General 7 05-21-2008 07:35 AM
Logging output from kdeinit Dyadya_Sam Linux - Newbie 3 06-06-2005 12:50 AM
logging tar output chakkerz Linux - Newbie 2 03-10-2004 12:42 AM
Logging output from DUMP chrisk5527 Linux - General 2 01-26-2004 07:30 PM


All times are GMT -5. The time now is 05:39 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