LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   How to Capture a Unix Terminal Session? (http://www.linuxquestions.org/questions/linux-server-73/how-to-capture-a-unix-terminal-session-4175410875/)

kalpeer 06-11-2012 10:48 AM

How to Capture a Unix Terminal Session?
 
Hi All,

I want to capture all the operations performed in the terminal. So to achieve this I used “script” command. This works as I expected. But this command captures all the standard output which is redirected to terminal. For example if i “tail” a file, even the tail output is getting captured. But I want to capture only the commands not the output. I don’t want to capture the Standard Output. Is there any way to capture only the commands that are typed in the terminal?

I don’t want use the bash history since it will not store TTY information. I have automated this process, whenever user logins a script will be started to capture the operations.

Thanks,
Kalai

divyashree 06-11-2012 12:02 PM

Quote:

Originally Posted by kalpeer (Post 4700708)
Hi All,

I want to capture all the operations performed in the terminal. So to achieve this I used “script” command. This works as I expected. But this command captures all the standard output which is redirected to terminal. For example if i “tail” a file, even the tail output is getting captured. But I want to capture only the commands not the output. I don’t want to capture the Standard Output. Is there any way to capture only the commands that are typed in the terminal?

I don’t want use the bash history since it will not store TTY information. I have automated this process, whenever user logins a script will be started to capture the operations.

Thanks,
Kalai

You can tweak the HISTFILE variable in user's rc/profile to save the command history on terminal number basis of each user.

Code:

TTY=$(tty | sed 's|/|_|g')
HISTFILE="~/.bash_history$TTY"


unSpawn 06-12-2012 01:27 PM

Quote:

Originally Posted by kalpeer (Post 4700708)
I want to capture all the operations performed in the terminal.

Have a look here?

kalpeer 06-12-2012 02:40 PM

Quote:

Originally Posted by divyashree (Post 4700742)
You can tweak the HISTFILE variable in user's rc/profile to save the command history on terminal number basis of each user.

Code:

TTY=$(tty | sed 's|/|_|g')
HISTFILE="~/.bash_history$TTY"


Thanks a lot this helped me..
But in history file a date is getting updated along with each command. Is it possible to remove all other data except command.

Quote:

#13000123
ls
#13000124
cd /tmp

unSpawn 06-16-2012 04:54 AM

Quote:

Originally Posted by kalpeer (Post 4700708)
I don’t want use the bash history since it will not store TTY information.

One of the rules of safe(r) programming says you should never trust user-submitted input. So no, you should not trust or rely on settings or files if the user owns them and can modify them at will.


All times are GMT -5. The time now is 10:14 AM.