LinuxQuestions.org
Register a domain and help support LQ
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-31-2009, 06:10 PM   #1
computer_freak_8
Member
 
Registered: Jul 2008
Location: Iowa
Distribution: Ubuntu and Fedora, mostly
Posts: 89

Rep: Reputation: 15
~/.bashrc variable for a command? Maybe?


Okay, here's what I'm trying to do: I'd like to have a sort of "keylogger", if you will, to help me see exactly what happened for every command I have typed. (This will be used to troubleshoot/author tutorials, when possible.)

I'm thinking of something simple like:
Code:
$command | tee -a terminal.log | $stdout
However, I see a few problems with this. First, I want it to be completely transparent, so that it appears as if it is just running the command, and scrolling any/all output to the terminal. Also, I want to write the command itself, and then the output of it.

In theory, this would basically be a log of everything that appears on the terminal, except the "username@host:~$" parts. Although, it would be fine by me if it did include the "username@host:~" parts.

****Edit: I would like something that I can append to my "~/.bashrc" file, so that I will not have to directly invoke it each time I open a terminal window.****

Last edited by computer_freak_8; 02-01-2009 at 03:19 PM. Reason: Add needed clarification.
 
Old 01-31-2009, 06:31 PM   #2
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 727

Rep: Reputation: 74
Hi.

See man script or Google linux man script ... cheers, makyo
 
Old 01-31-2009, 07:22 PM   #3
computer_freak_8
Member
 
Registered: Jul 2008
Location: Iowa
Distribution: Ubuntu and Fedora, mostly
Posts: 89

Original Poster
Rep: Reputation: 15
Thanks for the response.

I tried using script, but I can't quite seem to get it.
If I use this:
Code:
script -a /home/jaredtbrees/termlog.txt
Then I get this:
Code:
Script started, file is /home/jaredtbrees/termlog.txt
line after line after line, until I hit [Ctrl]+[C].

If I use this:
Code:
script -a -q /home/jaredtbrees/termlog.txt
Then I get only a blinking cursor - no "user@host:~$". Also, I cannot delete any text that I type, and the commands I type do not appear to do anything.

Either way, the file has no contents, even after issuing several commands.
Any suggestions?
 
Old 01-31-2009, 08:38 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531
Try 'rootsh' and make it log to a file?
 
Old 01-31-2009, 11:12 PM   #5
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 727

Rep: Reputation: 74
Hi.
Quote:
The script ends when the forked shell exits (a control-D to exit the Bourne shell (sh(1)), and exit, logout or control-d (if ignoreeof is not set) for the C-shell, csh(1)).

-- excerpt from http://linux.die.net/man/1/script
Best wishes ... cheers, makyo
 
Old 01-31-2009, 11:27 PM   #6
computer_freak_8
Member
 
Registered: Jul 2008
Location: Iowa
Distribution: Ubuntu and Fedora, mostly
Posts: 89

Original Poster
Rep: Reputation: 15
@makyo:
Yes, I read over that exact same page, and figured that that was the problem.

@unSpawn:
When I started my terminal, I received this message above the "user@host:~$" prompt:
Quote:
bash: rootsh: command not found
So, I will try to install "rootsh" when I get a chance. (I tried "sudo apt-get install root[TAB]", and it is not listed, so apparently it is not in the Ubuntu repositories.)

Thanks.
 
Old 02-01-2009, 11:14 AM   #7
101b147
LQ Newbie
 
Registered: Jan 2009
Distribution: Fedora
Posts: 24

Rep: Reputation: 15
it is as makyo said. control+c kill the current process. when you run the program, it writes everything to the file only when the program ands successfully. if you control+c, it won't write anthing to the fili. you must either use control+d to send and EOF signal, or type "exit".
 
Old 02-01-2009, 12:43 PM   #8
computer_freak_8
Member
 
Registered: Jul 2008
Location: Iowa
Distribution: Ubuntu and Fedora, mostly
Posts: 89

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by 101b147 View Post
it is as makyo said. control+c kill the current process. when you run the program, it writes everything to the file only when the program ands successfully. if you control+c, it won't write anthing to the fili. you must either use control+d to send and EOF signal, or type "exit".
But unless I kill the process, I am unable to use the terminal, making it useless in this context. Unless I missed something...

You may recall what I originally said about it:
Quote:
Originally Posted by computer_freak_8 View Post
If I use this:
Code:
script -a /home/jaredtbrees/termlog.txt
Then I get this:
Code:
Script started, file is /home/jaredtbrees/termlog.txt
line after line after line, until I hit [Ctrl]+[C].
What I meant by this is that it gives me the "Script started" line on my terminal, again, and again, and again, making my terminal unusable until I kill it. In addition, in my first post I mentioned:
Quote:
Originally Posted by computer_freak_8 View Post
I want it to be completely transparent
This would mean no "Script started" line at all.
 
Old 02-01-2009, 01:34 PM   #9
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 727

Rep: Reputation: 74
Hi.

Let us see if we can just get a transcript of a session into default collection file typescript.

Enter the command:
Code:
script
It looks like not much has happened, but now enter the following commands:
Code:
echo hi
wc
uname -a
echo hi | wc
exit
Do not enter control-c in the above sequence. That will stop the collecting. The last command
Code:
exit
that you entered will cause command script to halt.

What has happened is that command script begins watching your terminal. It captures the keystrokes you enter as well as results from the commands you have typed. It places all this data in default file typescript as well as appearing to normally place everything on the display.

So after the exit, you can cat, print, edit the file typescript as you wish.

If that's not what you want, then perhaps you can re-phrase your original question ... cheers, makyo
 
Old 02-01-2009, 02:46 PM   #10
101b147
LQ Newbie
 
Registered: Jan 2009
Distribution: Fedora
Posts: 24

Rep: Reputation: 15
Quote:
Originally Posted by computer_freak_8 View Post
But unless I kill the process, I am unable to use the terminal, making it useless in this context. Unless I missed something...

You may recall what I originally said about it:

What I meant by this is that it gives me the "Script started" line on my terminal, again, and again, and again, making my terminal unusable until I kill it. In addition, in my first post I mentioned:

This would mean no "Script started" line at all.

strange. when i run script, i only get one "Script started" and the terminal continues as normal.
 
Old 02-01-2009, 02:56 PM   #11
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 518

Rep: Reputation: 177Reputation: 177
Quote:
Originally Posted by computer_freak_8 View Post
This would mean no "Script started" line at all.
From the script man page:
Quote:
-q Be quiet.
I too, only get one "script started"
 
Old 02-01-2009, 03:16 PM   #12
computer_freak_8
Member
 
Registered: Jul 2008
Location: Iowa
Distribution: Ubuntu and Fedora, mostly
Posts: 89

Original Poster
Rep: Reputation: 15
Lightbulb

Yes, I can get it by directly invoking it...

Quote:
Originally Posted by makyo View Post
If that's not what you want, then perhaps you can re-phrase your original question ... cheers, makyo
What I'm looking for is a way to append something to my ~/.bashrc file, so that all sessions will be logged automatically. I now realize that I failed to specifically mention this, and although I did mention "~/.bashrc" in the title of the thread, I must not have been very clear. My apologies; no wonder why I wasn't getting what I was looking for! (I'm off to edit the original post.)
 
Old 02-01-2009, 03:26 PM   #13
computer_freak_8
Member
 
Registered: Jul 2008
Location: Iowa
Distribution: Ubuntu and Fedora, mostly
Posts: 89

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by 101b147 View Post
strange. when i run script, i only get one "Script started" and the terminal continues as normal.
Quote:
Originally Posted by norobro View Post
I too, only get one "script started"
As I realized after reading the last post by user "makyo", my original post was unclear. I have edited the original post, and also clarified here. Sorry about that!
 
Old 02-02-2009, 12:45 PM   #14
101b147
LQ Newbie
 
Registered: Jan 2009
Distribution: Fedora
Posts: 24

Rep: Reputation: 15
you can add the line to your bashrc: script -a whatever_file
but youll have to type 2 exit commands to end your session.
 
Old 02-02-2009, 04:14 PM   #15
computer_freak_8
Member
 
Registered: Jul 2008
Location: Iowa
Distribution: Ubuntu and Fedora, mostly
Posts: 89

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by 101b147 View Post
you can add the line to your bashrc: script -a whatever_file
but youll have to type 2 exit commands to end your session.
As I mentioned in this post, that did not work for me.
Maybe add in an "exit" command at the end of "~/.bashrc"? I'll try that here soon...
 
  


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
.bashrc personal environment variable hua Linux - Software 1 04-11-2008 04:12 AM
create a variable in the .bashrc file in my home directory coldbeerz Linux - Newbie 2 12-14-2007 10:48 AM
bashrc variable ovince Programming 1 04-25-2007 08:35 AM
how to add environment variable to .bashrc file hasan Linux - General 7 10-03-2003 05:43 PM
how to add environment variable to .bashrc file? hasan Red Hat 1 10-03-2003 02:37 PM


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