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
- alex@bender:/pwd$ echo 'test'
- alex@bender:/pwd$ ls
- alex@bender:/pwd$ cat some_file
- alex@bender:/pwd$ fsdfsdfsd
- test.txt some_file
- some file content
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()
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?