0

I have modified my rc.local script to run some python script at startup. This python script seems to be started successfully. As the script is running forever (intended) and I want to see what the script does, my question is:

Is there a way to access the shell that runs this script?

Yes, to see what is going on, I could log to some file, but what if that script needs to get input from the user via console?

Thanks for your help!

M. Beining
  • 99
  • 1
  • 9
  • Are you sure that your Python program has been started by a shell? This depends on how you wrote the startup code. You could find (say, with `pgrep`) locate your Python program and then find the PID of the parent process. And, I hope thta you don't run at startup a script which eventually asks manual user invention..... – user1934428 May 04 '20 at 08:43
  • The program has been started by adding `python xxx` to /etc/rc.local before `exit 0`. I find the id of the process with pgrep, but it seems I cannot bring it to front, e.g. with `fg` as it is not job. My script does not ask for user input, I am just curious if there is a way to bring the process back to some shell :-) – M. Beining May 05 '20 at 12:23

1 Answers1

0

You will not be able to interact with the script run by rc.local. But you can see what it does by logging its output into dedicated files:

python myscript.py > /home/myhome/log/myscript.log 2> /home/myhome/log/myscript.err

where error messages go into a separate log file.

Note that your script will be executed by root, having permissions and ownership accordingly.

Here's a link to an earlier answer about this with a method to log all outputs of rc.local.

Now you can see in your log file, if the execution stops due to the script demanding input or indeed crashing, and then you can fix the script accordingly.

If you don't want to mess with rc.local for testing, you could also first run it through crontab on your or root's account (scheduled execution by user, see man crontab). This might be easier for debugging, and you can start it through rc.local once it works as you want.

MiVyoo
  • 1
  • 2
  • Thanks for your detailed answer, unfortunately I do already know how to redirect stdout and errout to a log file. What I am interested in is to bring the program started with `rc.local` to the front (in a shell) to interact with it, if that would be necessary in some case. Or to know if it is not possible at all. :-) – M. Beining May 05 '20 at 12:26