how to run several python programs from ubuntu console? - python-3.x

I would like to run several python programs from a ubuntu console ..
I am using PuTTY ... to open the terminal from the server ..
I currently use npm to run the javaScripts programs. I would like to know how I can run python programs in ubuntu, and close the assignment while the program is still running.
I wish I could leave the python program running, even if I close the terminal

You need a terminal multiplexer like screen.
With:
screen -S mysession
you can start a session and launch your programs.
You can detach that session by pressing Ctrl+A followed by D.
You can get this session again with:
screen -r mysession

Related

Chromedriver closes after running nohup on google cloud

I have got a simple script which uses selenium and chromedriver. I have installed the chrome. When I run the script using the command nohup python3.7 -u main.py & tail -f nohup.out everything works; script works as it should. When I close the window of the google cloud ssh the scripts stop working. When I reopen the ssh and call tail -f nohup.out I receive such an error
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
(Session info: headless chrome=75.0.3770.142)
I was using the chrome version 87 and read that downgrading it should help, so I downgrade it to 75.
It is run on ubuntu, chrome and chromedriver version are 75. Is there such a command that would make chromedriver not close after closing the ssh window?
You can start processes in background in Linux. They will continue running even when you log off (which closing SSH window essentially is).
There are several ways:
Using bg & disown - as described here
Using screen as described here
You can go through entire thread to get more ideas. I'd recommend using bg & disown - it works well on Ubuntu provided by GCP however you can try out various solutions and pick the one that suits your needs the best.
From my experience - I was using screen for many things - including virtualbox and it worked - it may be more cumbersome if you want many processes to run in background but if that's just one its pretty easy.
Install screen: sudo apt install screen, run it with screen and treat it as another screen, run whatever you want and then just press ctrl + a d and you will be back to "original" shell. If you want to resume yor screen sessions type screen -r. You will find even more about using screen here.

Node wrapper to start a terminal application like vim, emacs, tmux

TLDR; how can I run a node process from the terminal, start a process from node, exit the node process and have the process be attached to the parent terminal?
I am writing a node terminal application which should end by starting a new terminal application (e.g. vim, emacs, tmux). I want this application to run as if is was executed manually in the terminal that started the node application.
My current workaround for tmux is to run the node application, which sets up a new tmux session and echoes a tmux attach-session command just before the application exists. The user can then type this command manually in the terminal and execute it. Now the tmux session runs attached to the terminal.
I would want to move the attach command into the node application, but have the same end results. I.e. the node application terminates and the tmux session runs attached to the terminal. This seems to me to be required to do the same for applications like emacs, vim, etc. Where I cannot decouple the setup and attach. (For all I know vim and emacs can handle this decoupling, and I would be interested in knowing, but the original question asks for a general solution for any terminal application).
By attached, I mean as if the command/program was executed manually in the terminal.
The POSIX exec solves this problem as #Amadan has commented above. This solution does not work on windows.
The following snippet shows an example of how to do this with the kexec module.
const kexec = require("kexec");
kexec("emacs -nw");

How to terminate terminal that is connected to a AWS box but still leave process on?

I have ssh'd into a ubuntu AWS box via terminal on mac. I have successfully setup the process I want to run in the box.
How do can exit out of terminal without killing the process running?
Thank you in advance.
P.S
New to linux and terminal on mac
Personally I use screen to get in/out of the system while keeping the processes running.
$ sudo apt install screen
To create a new screen:
$ screen -S screen_name
Then do something in your screen, for example running a program, editing files, downloading file with wget, etc.
Later if you want to exit the terminal without killing the running process, simply press Ctrl+A+D.
The process will kept running in the background inside the screen
To reconnect to the screen:
$ screen -R screen_name

Can I run a script on my Pi and keep it running when I close SSH?

I have a Raspberry Pi running Debian Lite (terminal only, no desktop). I've installed Node.js and am currently running a script by making an SSH connection through puTTY.
The problem is, when I close the puTTY window the script stops running. I need it to run when my desktop is turned off, otherwise having it on the Pi is pointless.
So far I have tried:
-Nohup | Appended the output but still stopped running when I closed the terminal.
Multiple options:
Install screen or tmux on the PI and start the job with those programs.
(or) Run the job with the nohup command:
nohup command
(or) Run the job in the background and use disown:
command &
disown %1
I recommend option 1.

Using script to automatically start program when the system boot up (linux, shell)

Here is the situation, I'm planning to use a simple script to start a program call "STAF", when the Suse system is fully booted. I have achieved this by putting it in the "/etc/init.d/", but this script is basically executed at the background, which means that I cannot see its progress.
When the "STAF" is started this way it works but it doesn't show any working progress when its running service (for example ping, or system backup), instead if I start the "STAF" manually by running the same script whit a terminal, the working progress of "STAF" can be seen on the terminal. Its sort of like the program needs to be started with a interactive terminal, but how can I make this starting process automatic and it should imitate human opening a terminal and run the script?
Sorry if I explained it poorly because its a confusing situation. Thanks.
First, go to the KDE Startup and Shutdown options under System Settings. Then add this command as a new startup script:
konsole -e bash nameofyourscript.sh
I believe the screen utility can do what you describe. Instead of running STAF on startup, you would run screen STAF. To open that terminal, you would run screen -ls to get the screen ID, and screen -r ... to open it.
(Disclaimer: I have not tried this.)

Resources