简体   繁体   中英

Run a Python Script in a new window from a shell script ubuntu

this may seem like a stupid question.

I want to run a python script in another command line window from a shell script file which opens all of my programs on one of my servers.

Currently the python scripts open in the same command line window where the shell script is being ran.

I've googled around a bit and haven't found anything related to this.

Thanks in advance.

If I understand correctly you have a server, which has a screen attached to it, and you made a shell screen to open a new terminal and run a given set of programs attached to that terminal.

It seems to me that you don't want this in a script but instead should be looking for an init system, such as systemd, which is available in Ubuntu. Simply put systemd initializes and kills processes running in the background (usually called daemons).

To create a systemd unit file, create a new file at /etc/systemd//system , let's name it example.service , and write the following to it:

[Unit]
Description=*Write description here*
Type=simple
Restart=always
RestartSec=1
User=*Write user here*
ExecStart=*Write command you wish to run here*

[Install]
WantedBy=multi-user.target

Now you can start this program in the background with:

$ systemctl daemon-reload
$ systemctl start example

You can also stop it from running:

$ systemctl stop example

And even enable it at boot time, so that it persists shutdown/reboot:

$ systemctl enable example

You can obtain the output for this program with:

$ systemctl status example

For more information regarding systemd and all of the config options you can either look in the man page with man systemd (very long) or google for a specific issue or feature you wish to implement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM