Mainscript 在新终端中执行 subscripts window
Mainscript executes subscripts in a new terminal window
"Debian 9 64x - LXDE"
我尝试在 bash 中创建安装脚本。假设我想安装 samba。我从主脚本调用 samba \folder\samba.sh
的安装脚本。脚本 samba.sh 应该在新终端 window 中执行,所以我可以观察安装错误。
脚本应该像下面描述的那样工作:
- 脚本
/mainscript.sh
只提供用户信息,交互,执行多个下标(/folder/subscripts.sh
)。
- 脚本
/mainscript.sh
需要创建一个新的终端window,传递路径和subscript.sh
的名称并在新终端window中执行它们。
- 脚本
/mainscript.sh
一次只能执行一个下标(/folder/subscript.sh
)!如果 subscript.sh
是 运行 那么主脚本必须等到新终端 window 关闭。
subscript.sh
以 root 权限执行一些代码。
问题:
如何新建终端window,传入下标,在新终端执行window?
如何确保脚本(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
在澄清您实际上想要一个新终端 window 出现在 LXDE 之后,这是一个可能的解决方案。
Debian LXDE 可能安装了 xterm 或 lxterminal。下面的示例使用 lxterminal。对于 xterm 使用 "xterm -e command"
首先在自己的 window 中执行 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 完成后,新终端 window 将关闭并且 return 控制权交给 mainscript.sh
通过依次调用它们,您一次只能获得 运行 的一个下标。
"Debian 9 64x - LXDE"
我尝试在 bash 中创建安装脚本。假设我想安装 samba。我从主脚本调用 samba \folder\samba.sh
的安装脚本。脚本 samba.sh 应该在新终端 window 中执行,所以我可以观察安装错误。
脚本应该像下面描述的那样工作:
- 脚本
/mainscript.sh
只提供用户信息,交互,执行多个下标(/folder/subscripts.sh
)。 - 脚本
/mainscript.sh
需要创建一个新的终端window,传递路径和subscript.sh
的名称并在新终端window中执行它们。 - 脚本
/mainscript.sh
一次只能执行一个下标(/folder/subscript.sh
)!如果subscript.sh
是 运行 那么主脚本必须等到新终端 window 关闭。 subscript.sh
以 root 权限执行一些代码。
问题:
如何新建终端window,传入下标,在新终端执行window?
如何确保脚本(
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
在澄清您实际上想要一个新终端 window 出现在 LXDE 之后,这是一个可能的解决方案。
Debian LXDE 可能安装了 xterm 或 lxterminal。下面的示例使用 lxterminal。对于 xterm 使用 "xterm -e command"
首先在自己的 window 中执行 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 完成后,新终端 window 将关闭并且 return 控制权交给 mainscript.sh 通过依次调用它们,您一次只能获得 运行 的一个下标。