【问题标题】:Mainscript executes subscripts in a new terminal windowMainscript 在新的终端窗口中执行下标
【发布时间】:2019-03-28 13:00:34
【问题描述】:

“Debian 9 64x - LXDE”

我尝试在 bash 中创建安装脚本。假设我想安装 samba。我从主脚本调用 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)?

示例:

mainscript.sh

    #!/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.sh

    #!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.sh

    #!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】:

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

    Debian LXDE 可能安装了 xterm 或 lxterminal。下面的示例使用 lxterminal。对于 xterm 使用“xterm -e 命令”

    首先在自己的窗口中执行 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 通过依次调用它们,您一次只能运行一个下标。

    【讨论】:

    • 目标是同时打开两个 Windows 终端。窗口(A)显示 mainscript.sh 中执行的代码。 window(B) 显示 subscripts.sh 中执行的代码
    • 这不起作用。 xterm: No absolute path found for shell: /opt/subscript.sh
    • 你有安装 lxterminal 吗?然后替换为“lxterminal --command=/pathto/scripth.sh”
    • ...或尝试“xterm -e /pathto/script.sh”。见:unix.stackexchange.com/questions/269351/…
    猜你喜欢
    • 2013-10-18
    • 1970-01-01
    • 1970-01-01
    • 2014-05-27
    • 1970-01-01
    • 2022-01-16
    • 2015-08-15
    • 1970-01-01
    相关资源
    最近更新 更多