0

I have the following:

  1. main.py python script which while running writes to main.log.
  2. I am writing a sh file.

I want to execute the python script from sh file and to see in the terminal window all the log which is written to the main.log file while executing.

Currently I am doing it by open a terminal and execute the script and open another terminal and writing

tail -f main.log.

Thanks.

3
  • Simply use & after the command you use for launching your python script to launch it as a background process. Then, you can tail -f in the same terminal. Commented Feb 4, 2016 at 12:45
  • could you change your script to log to stdout instead? You can redirect the output to terminal and a file later if necessary: python main.py | tee main.log. Commented Feb 4, 2016 at 15:41
  • @J.F.Sebastian: You're right, that's done. Commented Feb 4, 2016 at 15:52

2 Answers 2

1

Simply use & after the command you use for launching your python script to launch it as a background process. Then, you can tail -f in the same terminal.

Sign up to request clarification or add additional context in comments.

2 Comments

I still have a problem where I make the "sudo python3 ... & sudo tail -f Main.log", it does the work and shows me the log to the terminal. The thing is that after this command, I have to run another command in the continue of the script, but the tail -f runs without ending and the next command in the script doesn't get executed. How can I solve it ? Thanks.
You probably should read some bash scripting tutorial past this point.
0

I've used the nohup command in the past to essentially disconnect from a process and let it run in the background. The syntax would be something along the lines of nohup <program execution and options> > main.log &

Then you can tail -f main.log to watch it update in real time.

I've had issues with nohup where a .sh either runs infinitely or has a syntax error, so definitely check for correctness before running. You probably won't catch this unless you change the end of the statement to 2>&1 & to get stderr to redirect to stdout, but since you're running a python script, I don't think this would help you.

Lastly, you can kill the process created by nohup by either killing the PID given to you by the command, or using ps -ef | grep <main.log>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.