1

in console I run pgrep python | xargs ps and it shows me 2 python scripts running on background. But how can I show output of each script on console?

P.S. I just want to see last printed outputs from scripts to know if scripts are running fine or printed some exceptions or my messages.

Additional subquetion - What in case, when scripts are automatically executed via rc.local on boot? Is there any way how to get screen for these scripts?

  • 1
    Where is the output going now? – PiedPiper Dec 7 '17 at 14:16
  • now it is standard console, I mean when I run the script from command line, it shows me output. But when I log off from ssh and then log in again (script is running from previous), then I dont see output anymore for that script. – peter Dec 7 '17 at 14:33
  • How do you run the scripts? – 123 Dec 7 '17 at 15:02
  • An answer is "use screen" but I'm sure there's a duplicate out there with some proper instructions. Related - unix.stackexchange.com/questions/22781/… – roaima Dec 7 '17 at 16:26
  • And what in case, when scripts are automatically executed via rc.local on boot? Is there any way how to get screen for these scripts? – peter Dec 8 '17 at 8:35
6

The easiest way is to use screen or tmux. Both allow you to disconnect from a running session while maintaining the terminals your scripts are using for output. To use either, simply type tmux (or screen) when you connect with ssh (you might have to install tmux first but most distributions have these tools available in default repositories) and then run your script as usual. If you disconnect, run tmux attach again after reconnecting with ssh to restore your previous session.

  • I didn't know this. Thanks looks nice. But what in case, when scripts are automatically executed via rc.local on boot? Is there any way how to get screen for these scripts? – peter Dec 7 '17 at 17:07
  • If scripts are executed outside of interactive sessions (rc.local, cron, running as a daemon, etc.) you should redirect their output to a file or implement proper logging. – Denis Dec 8 '17 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.