Log all terminal commands in file - linux

I've tried this solution: https://askubuntu.com/a/858319
It works good but the only trouble with syslog is that commands from SCREEN can't be logged.
If someone tried anything else, or knows better way to log all inputted commands in Linux terminal?

Use script. It saves everything including the output.

Related

Python Terminal Calls Fail to Interact with Files

I am writing a program that handles some data on a server. Throughout the program, many files are made and sent as input into other programs. To do this, I usually make the command string, then run it like so:
cmd = "prog input_file1 input_file2 > outputfile"
os.system(cmd)
When I run the command, however, the programs being called report that they cannot open the files. If I run the python code on my local computer, it is fine. When I loaded it onto the server, it started to fail. I think this is related to issues with permissions, but am not sure how I can fix this. Many of the files, particularly the output files, are being created at run time. The input files have full permissions for all users. Any help or advice would be appreciated!
Cheers!
The python code you list is simple and correct, so the problem is likely not in the two lines of your example. Here are some related areas for you to check out.
Permissions
The user running the python script must have the appropriate permission (read, write, execute). I see from comments that you've already checked this.
What command are you running
If the command is literally typed into your source code like in the example, then you know what command is being run, but if you are generating any part of it (eg. the list of operands, the name of the output file, other parameters, etc), make sure there are no bugs in the portions of your code that generate the command. For example before the call to os.system(cmd) consider including a line like print("About to execute: " + cmd) so you can see exactly what will be run.
Directly invoke the command
If all the above looks good, try to execute the command directly at a terminal on your server. What output do you get then. It's possible that the problem is with the underlying command itself rather than your python code.

Access output in Ubuntu 14.04 terminal that has 'disappeared' off the terminal window

I just ran a script on a server that generates a lot of output on the command window.
However, now, after running it for roughly 4 hours I want to check all the output, but the beginning of the output has already disappeared from the terminal window. When I scroll up, it is not there anymore.
Is there any way to access this? It needs to be via commands in the terminal because I'm running it on a server.
Thanks.
Best way is to redirect the output to a file & open the file to check for all the output.
You can also redirect the script by running it in background & saving the output to a file. Do let me know what type of command you are running for which I can give you the exact command. :)
if it's a real terminal and not a virtual terminal
you need to recompile your kernel and increase the buffer size of your terminal.
in the .config file of your kernel the parameter you need to increase is
CONFIG_VGACON_SOFT_SCROLLBACK_SIZE
Actually, redirecting I/O interferes with many programs (for instance, changing the output from a tty to a plain file). Use the script program to capture all output from programs run in a shell, with minimal interference.

log every linux command line ever used?

so, I'm solid on linux basics, and have never written a shell script. But there is something I would like to get, or do.
Would it be possible to have linux log ALL COMMANDS I EVER TYPE in a single file? I.e., every ls -l and cd /this/folder etc., but also the install records I have done and more.
If this file exists great. If there is a persistent file created for EACH session and user, then maybe I can write a script to conjoin the lines. Or, what other options are available?
I'd like the file to have 3 columns, user executing, datetime executed, and copy of the command string. Some kind of results or error if returned would be great. MANY THANKS from a guy who is amazed what Linux is capable of doing!
Assuming you're running bash, look at your ~/.bash_history file.

Run a Command When Terminal Opens (Linux)

This feels like a stupid question, but I can't find an answer (that works) anywhere. So, I thought I'd ask it here.
Basically, I would like a command to run every time I open a Terminal window, and then show the output in the Terminal (I have Fedora). Is this possible with the MOTD, or is that text-only?
Thanks!
Put it in ~/.bashrc or equivalent.

Is there a Linux command to replicate/replace the "banner" command?

I am writing a script on Red Hat Linux (I forget the version) that needs a header, but the banner command is not there for me to use and I won't be able to get it installed. I read via Google that it may well have been deprecated.
So is there a new version of the command that produces similar results, or a way I can replicate the command, or even just temporarily change the script output so that characters are a different size?
I've tried looking at stty but we don't access via xterm, we log in directly via putty.
In its simplest form, 'banner' is less than a few pages of code (e.g. this one). Perhaps you could just compile and run it from your home directory?
Use some web site, for example http://patorjk.com/software/taag/.
If you need it frequently you can create a script to scrap the result.
BTW, stty has nothing to do with your problem, I don't know why you mentioned it.

Resources