Felipe
Felipe

Reputation: 7563

how to make a script with log files

I have a script that generates various outputs on the console, it runs various commands and programs.

I'm looking for a way to put all console output into a log file. But he did not want the ". / MeuScrip >> log.txt". Also use ". / Myscript | tee log.txt". but this hide questions confirmation of programs (y|n).

I wanted to configure the log file in my script. Does anyone have a solution for this?

thank you Felipe

Upvotes: 0

Views: 330

Answers (1)

V H
V H

Reputation: 8587

if the script prompts then unsure how you can capture something interactive beyond the question. Meaning it will only get far as (y/n) then halt waiting for human input, anyhow won't get too involved give this a try ./MenuScrip 2>&1 > ./log.txt

the only problem with that is all out put is going there and you may not get to see the prompt yourself.

why not edit the script itself and put logging into the script so what ever the user chooses or script does it logs to a log file meaning at edit the script declare a log file at the top then what ever u wish to log capture command/input and send to log file as well as carry out

all the best

edited to add:

if the script is a binary file and assuming this is for monitoring purposes i.e. to overlook what others have actioned you could::

Make user sudo as another user

Running the later versions of sudo comes with sudoreplay - this will let you play back their entire key by key input/actions you could then replay the sudo files when required

Upvotes: 2

Related Questions