Hi there!
I need to capture all command, stdout and stderr without any addition to the commands.
I mean, that I have to save/store the output of these:
- $ echo 'test'
- $ ls -l
- $ cat some_file
commands.file
- alex@bender:/pwd$ echo 'test'
- alex@bender:/pwd$ ls
- alex@bender:/pwd$ cat some_file
- alex@bender:/pwd$ fsdfsdfsd
stdout.file
- test
- test.txt some_file
- some file content
stderr.file
_4. fsdfsdfsd
as for first part of question, I found script, which use a trap and before evaluating the command it stores the command to log.
But what about storing output?
repeat: this should be solved without any additions to command.
I mean, after running script, I dont need to write, for example first command
ls > log.file I want see it without ">log.file"
I write some python script, it works like command wrapper.
if name == 'main':
user = os.getlogin()
machine_name = os.uname()[1]
stdinbuff = open('commands', 'w')
stdoutbuff = open('outs', 'w')
command_string = 1
while command_string != '0':
a = user + '@' + machine_name + ":" + os.getcwd() + '>';
a = a.replace('/home/', '~/')
print a,
command_string = raw_input()
command_args = command_string.split()
proc = subprocess.Popen(command_args, stdout=subprocess.PIPE)
(out, err) = proc.communicate()
print out
stdinbuff.write(command_string+'\n')
stdoutbuff.write(out+'\n')
stdinbuff.close()
stdoutbuff.close()
but in this wrapper, I can't use autocomplete, like in bash, and this script can't store all what I want.
Maybe, someone could tell me, what I have to do?
Best Answer
Maybe the
screen
tool can do the trick for you with the screen logging function. Just simply startscreen
in commandline and with the keysCTRL-a + H
(first Combination ofCTRL + a
and then a capital H withSHIFT + H
, just to clarify) everything will be logged in the filescreenlog.0
. The directory where the logfile is found depends on where you started screen, i. e. if you started screen in your $HOME then the logfile will be found there.