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:

  • How can I create a new terminal window, pass the subscript, and execute it in the new terminal window?
  • How can I make sure that the script (mainscript.sh) only runs one subscript (subscript.sh) at the time?

This example should only clarify what i wanna do, it doesnt work !:

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)))"
x-terminal-emulator /opt/subscript1.sh
echo "samba - Installed"
x-terminal-emulator /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
  

Can someone help ?

So, what happens? What does your code do?

English is not my first language, so maybe its not clear what i asking for. :o

It doesnt work at all thats my problem ...
And i don't know what im doing wrong ... The example is only to show how it should work....

In what way does it "not work"? Do you get any error messages? How are you running it?

Did you consider the -e option? man xterm :

xterm waits for the command to be finished before it returns control to the caller / shell / main script, so your second request should be fulfilled by default.

Yes i tested the -e option aber it doesnt work too.

Is this code line not a comment ? Is this code line required that the scripts run ?

#!/bin/sh
  

I didn't wrote this line in the subscript. Now it executes the subscript correctly.

"echo test" and the "subscript" gets executet at the same time
"echo test" should not get executet because of "read" the terminal window of the subscript stays open:

#!/bin/bash
# mainscript
 x-terminal-emulator -e ./abc.sh
echo "test"

 
#!/bin/bash
# subscript
echo "ABC"
echo "EFG"
read
  

Thanks for the Help.

This is the second time you've said 'does not work' without explaining. Please try to work with us. We're running blind here.

It is hard to explain a problem when i don't get an error. The created terminal window got open and got closed instant. I only saw a flash of the new terminal window. but i get this solved now with adding #!/bin/bash
Please read my last post again. The problem now is that the "echo" command gets executed at the same time the subscript gets executed, but it needs to wait until the terminal window of the subscript gets closed. How can i get this done ?

Thank you.

Try like

x-terminal-emulator -hold -e ls; echo test

This doesn't close the xterm window, and echo test is executed only after xterm is closed by external action.

The LXTerminal doesn't have the -hold option. Do i need to switch to a other terminal emulator like xterm in that case ?

I know that i need to add exit to close the terminal window of the subscript.

That is far more useful to know than nothing.

That is also far more useful to know than nothing.

Thanks for the Help,

I noticed that it is not possible to execute scripts and -hold in the LXTerminal. The -hold option doesnt exist in LXTerminal.

This solution works now:

#!/bin/bash
#mainscript

xterm -e "./abc.sh"
echo "test"
#!/bin/bash
#subscript

echo "ABC"
echo "DEF"
read -p "Press any key to close this window"
  

Thank's to all for the help!

Making fools out of people in here doesn't really help. You mentioned problems with xterm explicitly in post #1 before editing it away. lxterminal showed up in post #10 only. Waste of time, yours and ours.

I did only try to clarify my problem. It was not my intention to make fools out of any people.