Search code examples
bashterminaldebiansubscript

Mainscript executes subscripts in a new terminal window


"Debian 9 64x - LXDE"

I try to create an install script in bash. Lets assume i want to install samba. I call from the mainscript the install script for samba \folder\samba.sh. The script samba.sh should get executed in a new terminal window, so i can watch for install errors.

The script should work like follow description:

  • The script /mainscript.sh provides only user information, interaction, and executes multiple subscripts (/folder/subscripts.sh).
  • The script /mainscript.sh needs to create a new terminal window, passes the path, and the name of subscript.sh and executes them in the new terminal window.
  • The script /mainscript.sh must only execute one subscript (/folder/subscript.sh) at the time! If a subscript.sh is running then the mainscript must wait until the new terminal window gets closed.
  • The subscript.sh executes some code with root privileges.

Questions:

  1. How can I create a new terminal window, pass the subscript, and execute it in the new terminal window?

  2. How can I make sure that the script (mainscript.sh) only runs one subscript (subscript.sh) at the time?

Example:

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

Solution

  • After clarification that you actually want a new terminal window to appear in LXDE here is a possible solution.

    Debian LXDE is likely to have xterm or lxterminal installed. The example below is using lxterminal. For xterm use "xterm -e command"

    Start by executing manscript.sh in its own window:

    $ lxterminal --command=/mainscript.sh
    
    #!/usr/bin/sh
    
    <section that provides user information>
    
    # Call subscripts that will run in sequence
    lxterminal --command=/folder/subscripts.sh
    
    

    When subscripts.sh finishes, the new terminal window will close and return control to mainscript.sh You get only one subscript to run at a time by calling these in sequence.