Run multiple .sh scripts from one .sh script? CentOS

。_饼干妹妹 提交于 2020-01-04 09:19:55

问题


How can I run multiple .sh scripts from one .sh script and run them all in separate terminals? I already have

/root/A.sh & /root/B.sh & /root/C.sh

The issue is it runs all of these in the same terminal at the same time, and without the &'s, it runs them when the previous one is finished running, how can I make them all startup at the same time in separate terminals?


回答1:


Here is one way leveraging gnome terminal tabbing capability :

gnome-terminal \
  --tab-with-profile=Default --title=A.sh --command="/root/A.sh" \
  --tab-with-profile=Default --title=B.sh --command="/root/B.sh" \
  --tab-with-profile=Default --title=C.sh --command="/root/C.sh"&



回答2:


You can launch your preferred terminal program (i.e. rxvt, xterm, etc) and pass the command to be executed as an option, as in (for instance):

rxvt -display :0 -e "/root/B.sh"&

This assumes you're running on the local console with an X server and window manager.




回答3:


I'm not at my pc right now, so I can't test this...

Try including the following in your main script to start sh (or whatever shell you prefer) invoking your script as a background task to stop the main script blocking.

sh script1 &
sh script2 &
sh script3 &

Kev




回答4:


With konsole, you can have

konsole -e command [args]

e.g.

konsole -e /bin/bash root.sh &  ## For konsole, placing it on the background is optional

You can also set the window's title (depends on the version)

konsole -p tabtitle="Window title." -e command [args]

With xterm:

xterm -e command [args] &  ## xterm needs to be placed on background.



回答5:


Here is a tutorial on how to configure screen for multiple shell sessions and here is another tutorial on using screen

edit

you can check this for using screen and 2 other alternatives for multiprocessing shell



来源:https://stackoverflow.com/questions/18669866/run-multiple-sh-scripts-from-one-sh-script-centos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!