Mainscript在新的终端窗口中执行下标

问题描述 投票:0回答:1

“Debian 9 64x - LXDE”

我尝试在bash中创建一个安装脚本。让我们假设我想安装samba。我从mainscript调用samba \folder\samba.sh的安装脚本。脚本samba.sh应该在新的终端窗口中执行,所以我可以监视安装错误。

该脚本应该像以下描述一样工作:

  • 脚本/mainscript.sh仅提供用户信息,交互,并执行多个下标(/folder/subscripts.sh)。
  • 脚本/mainscript.sh需要创建一个新的终端窗口,传递路径和subscript.sh的名称,并在新的终端窗口中执行它们。
  • 脚本/mainscript.sh当时只能执行一个下标(/folder/subscript.sh)!如果subscript.sh正在运行,那么主语必须等到新的终端窗口关闭。
  • subscript.sh使用root权限执行一些代码。

问题:

  1. 如何创建新的终端窗口,传递下标,并在新的终端窗口中执行它?
  2. 我怎样才能确保脚本(mainscript.sh)当时只运行一个下标(subscript.sh)?

例:

main script.是

    #!/bin/sh
    # This is the content of the mainscript.sh
    # subscript1 and subscript2 must not be executed at the same time!
    # the mainscript needs to wait when a subscript gets executed!

    echo "hello, this script runs in terminal window (((A)))"
    xterm /opt/subscript1.sh
    echo "samba - Installed"
    xterm /opt/subscript2.sh
    echo "samba - removed"

subscript1.是

    #!bin/sh
    # This is the content of the subscript1

    echo "This script runs in a new terminal window (((B)))"
    apt-get install samba
    # instructions done .... close the terminal window (((B))) now

subscript2.是

    #!bin/sh
    # This is the content of the subscript2

    echo "This script runs in a new terminal window (((C)))"
    apt-get remove samba
    # instructions done .... close the terminal window (((C))) now
bash terminal debian subscript
1个回答
0
投票

在澄清您确实希望在LXDE中出现新的终端窗口之后,这是一个可能的解决方案。

Debian LXDE很可能安装了xterm或lxterminal。以下示例使用lxterminal。对于xterm使用“xterm -e command”

首先在自己的窗口中执行manscript.sh:

$ lxterminal --command=/mainscript.sh
#!/usr/bin/sh

<section that provides user information>

# Call subscripts that will run in sequence
lxterminal --command=/folder/subscripts.sh

当subscripts.sh完成时,新的终端窗口将关闭并将控制权返回给mainscript.sh通过按顺序调用它们,您一次只能运行一个下标。

© www.soinside.com 2019 - 2024. All rights reserved.