![Gnu 화면에서 탭 창을 열고 각 창에서 명령을 실행하는 방법](https://rvso.com/image/31669/Gnu%20%ED%99%94%EB%A9%B4%EC%97%90%EC%84%9C%20%ED%83%AD%20%EC%B0%BD%EC%9D%84%20%EC%97%B4%EA%B3%A0%20%EA%B0%81%20%EC%B0%BD%EC%97%90%EC%84%9C%20%EB%AA%85%EB%A0%B9%EC%9D%84%20%EC%8B%A4%ED%96%89%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95.png)
다음과 같은 이름의 세션을 시작할 때screen -S name1
다음과 같이 그놈 터미널에서 탭을 열 때처럼 이 화면 세션에서 탭 창을 열고 싶습니다.
gnome-terminal --tab -e "some commands"
그럼 이걸 어떻게 하지?
답변1
1. 화면의 탭
.screenrc 파일에 추가할 항목을 찾고 있습니다.
screen -t tab1
screen -t tab2
상태 표시줄 등을 시작하는 데 도움이 되는 멋진 기본 .screenrc가 있습니다.메모:이는 일반적으로 홈 디렉토리에 있습니다 /home/<username>/.screenrc
.
screen -t validate #rtorrent
screen -t compile #irssi
screen -t bash3
screen -t bash4
screen -t bash5
altscreen on
term screen-256color
bind ',' prev
bind '.' next
#
#change the hardstatus settings to give an window list at the bottom of the
#screen, with the time and date and with the current window highlighted
hardstatus alwayslastline
#hardstatus string '%{= kG}%-Lw%{= kW}%50> %n%f* %t%{= kG}%+Lw%< %{= kG}%-=%c:%s%{-}'
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'
스크린샷
2. 화면의 탭(내부에서 실행되는 명령 포함)
아래 예 .screenrc
에서는 탭 2개를 만들고 각 탭에서 3개의 echo 명령을 실행합니다.
screen -t tab1
select 0
stuff "echo 'tab1 cmd1'; echo 'tab1 cmd2'; echo 'tab1 cmd3'^M"
screen -t tab2
select 1
stuff "echo 'tab2 cmd1'; echo 'tab2 cmd2'; echo 'tab2 cmd3'^M"
altscreen on
term screen-256color
bind ',' prev
bind '.' next
#
#change the hardstatus settings to give an window list at the bottom of the
#screen, with the time and date and with the current window highlighted
hardstatus alwayslastline
#hardstatus string '%{= kG}%-Lw%{= kW}%50> %n%f* %t%{= kG}%+Lw%< %{= kG}%-=%c:%s%{-}'
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'
select
이 기술은 화면 과 명령을 사용하여 stuff
처음에 탭 중 하나를 선택한 다음 그 안에 문자열을 "채웁니다".
스크린샷
.screenrc
3. 파일을 사용하지 않고 #2 만들기
다음과 같은 시나리오를 찾고 있다면:
- 스크린 세션 생성
- 탭으로 로드하세요
- 각 탭에서 자체 명령을 실행하도록 하세요.
.screenrc
파일 이 필요하지 않습니다
그렇다면 이것은 당신을 위한 것입니다! 그래도 준비하세요. 이것은 명령줄을 사용하면 약간 까다로울 수 있습니다.
우선 스크린 세션을 만들어 보겠습니다.
$ screen -AdmS myshell -t tab0 bash
스위치는 -AdmS
다음을 수행합니다.
(참조스크린 매뉴얼 페이지상세 사항은)
-ㅏ
Adapt the sizes of all windows to the size of the current terminal. By default, screen tries to restore its old window sizes when attaching to resizable terminals
-d -m
Start screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts.
-S 세션 이름
When creating a new session, this option can be used to specify a meaningful name for the session. This name identifies the session for "screen -list" and "screen -r" actions. It substitutes the default [tty.host] suffix.
이제 탭과 해당 명령을 사용하여 로드를 시작하겠습니다.
$ screen -S myshell -X screen -t tab1 vim
$ screen -S myshell -X screen -t tab2 ping www.google.com
$ screen -S myshell -X screen -t tab3 bash
이 3개의 명령은 3개의 추가 탭을 생성하고 vim을 실행하고 google에 ping을 실행하고 bash 셸을 시작합니다. 스크린 세션을 나열하면 다음이 표시됩니다.
$ screen -ls
There is a screen on:
26642.myshell (Detached)
1 Socket in /var/run/screen/S-root.
스크린 세션에 연결하면,마이셸을 클릭하고 포함된 탭을 나열하면 다음이 표시됩니다.
$ screen -r myshell
이 키 조합을 누르십시오: Ctrl+ A다음에 Shift+"
Num Name Flags
0 tab0 $
1 tab1 $
2 tab2 $
3 tab3 $
다음으로 전환 중탭2:
64 bytes from ord08s08-in-f20.1e100.net (74.125.225.116): icmp_seq=443 ttl=55 time=41.4 ms
64 bytes from ord08s08-in-f20.1e100.net (74.125.225.116): icmp_seq=444 ttl=55 time=33.0 ms
64 bytes from ord08s08-in-f20.1e100.net (74.125.225.116): icmp_seq=445 ttl=55 time=30.1 ms
스크린샷
위의 명령은 OP가 찾고 있던 것을 달성하는 기본 방법입니다. 물론 이것은 Bash 별칭이나 쉘 스크립트를 사용하여 압축하고 개선할 수 있습니다. 이는 단지 기능을 보여주고 방법을 보여주기 위한 것입니다!
참고자료
답변2
답변에 작은 추가 사항입니다. stuff는 먼저 명령을 에코한 다음 이를 명령줄에 넣은 다음 \n 또는 ^M이 줄을 끝내면 실행합니다.
에코가 나를 짜증나게 했기 때문에 마지막 명령으로 \nclear\n을 연결하여 화면 창이 깨끗하게 시작되도록 했습니다.