1753416 Members
5086 Online
108793 Solutions
New Discussion юеВ

Re: Capture Session

 
SOLVED
Go to solution
Allanm
Super Advisor

Capture Session

Hi All,

I am in need to capture session data (commands and output which are executed during that login session) and put that in a file(date wise saved).

Shell is tcsh. Has anyone setup something like that using script command?

Please suggest.

Thanks,
Allan.
9 REPLIES 9
James R. Ferguson
Acclaimed Contributor
Solution

Re: Capture Session

HI Allan:

# man script

Since 'script' is a standalone utility, you can execute it in/from any shell.

Regards!

...JRF...
Mel Burslan
Honored Contributor

Re: Capture Session

As James said, you can use script command without any reservations, but looking at your post, I have a suspicion that you want to use this tool/contraption to log anf monitor the user activity.

If this is your intention, keep in mind that, when you execute the script command, the typescript file (or any other name you choose) gets created by the ownership of the user, who is running the shell. Hence, it is open to modification by the user. So, if they chose to delete lines out of it, they can do it without anyone else noticing.

If what you are doing is just to document what you are doing while in the shell, script utility is perfectly fine for it.

HTH
________________________________
UNIX because I majored in cryptology...
Allanm
Super Advisor

Re: Capture Session

I tried adding to my .bashrc but it goes into a loop and I am not able to exit out -

script -a /tmp/log

Is there a proper implementation of this command?

Thanks,
Allan.
Dennis Handly
Acclaimed Contributor

Re: Capture Session

>I tried adding to my .bashrc but it goes into a loop and I am not able to exit out

I don't think you can. The user must invoke it manually.
Is it the last command in .bashrc?
Allanm
Super Advisor

Re: Capture Session

yes its the last command.

Is there something which I can put in .bashrc or .cshrc to record commands and output and route it to a file?

Thanks,
Allan.
Dennis Handly
Acclaimed Contributor

Re: Capture Session

>Is there something which I can put in .bashrc or .cshrc to record commands and output and route it to a file?

Well. in a real shell you set use "set -x" to record execution of commands.
Allanm
Super Advisor

Re: Capture Session

Thanks for replying Dennis, is there a tcsh shell equivalent of set -x?

Regards,
Allan.
Dennis Handly
Acclaimed Contributor

Re: Capture Session

>is there a tcsh shell equivalent of set -x?

For the scummy C shell there is:
set echo

See the "-x" command option.
And for -v: set verbose
INH
Regular Advisor

Re: Capture Session

#script /tmp/xyz.txt
#command 1
#command 2
.
.
.
.
.
.
#commandn
#exit

you will have the output in /tmp/xyz.txt file

you may refer man pages of script
Knowledge is power