byobu를 사용하여 원격 서버에 연결하고 명령을 실행합니다.

byobu를 사용하여 원격 서버에 연결하고 명령을 실행합니다.

나는 일반적으로 ssh를 사용하여 연결하는 원격 서버를 가지고 있으며 연결 후 byobu가 자동으로 시작됩니다(스크립트를 사용하여 설정된 .profile의 라인을 통해 byobu-enable). 이제 원격 jupyter 노트북을 사용하기 위해 동일한 서버에 연결할 때 다른 워크플로를 설정하고 싶습니다. 원격 서버가 jupyter를 시작한 다음 ssh가 jupyter포트를 내 클라이언트 시스템으로 전달하도록 하고 싶습니다 . 내 로컬 .ssh/config에 추가했습니다.

Host remote-server-jupyter
    HostName      123.45.6.789
    User          pgcudahy
    LocalForward  8889 localhost:8889
    ServerAliveInterval 30
    ServerAliveCountMax 3
    RemoteCommand cd ~/Projects && jupyter notebook --no-browser --port=8889

문제는 "RemoteCommand"가 byobu 시작을 방해하므로 명령을 연결하고 실행한 후에는 멋진 멀티플렉스 화면 대신 일반 텍스트 셸이 남게 된다는 것입니다. 연결된 동안 byobu 및 원격 명령을 모두 얻는 방법은 무엇입니까?

중요한 점은 특정 작업 흐름이 필요하다고 지정하지 않는 한 모든 연결에서 이러한 명령이 실행되는 것을 원하지 않는다는 것입니다. 분명히 byobu에 연결한 다음 서버에서 스크립트를 실행하여 작업 공간을 설정할 수 있지만 이 모든 것을 클라이언트에서 하나의 자동화된 명령으로 래핑하고 싶습니다. 더 좋은 점은 사용자 정의 명령을 실행할 뿐만 아니라 여러 창과 각 창에 다른 명령이 있는 사용자 정의 byobu 작업 공간을 설정하는 별도의 구성 파일을 갖는 것입니다.

답변1

답변의 핵심은이 스택 오버플로 질문. ssh -t대화형 의사 터미널을 열려면 이 플래그를 사용합니다 . 그런 다음 명령을 byobu 세션에 byobu new-session전달합니다 .byobu send-keys

먼저 .ssh/config를 만듭니다.현지의기계가 SSH 연결을 설정합니다.

Host remote-server-jupyter
    HostName      123.45.6.789
    User          pgcudahy
    LocalForward  8889 localhost:8889
    ServerAliveInterval 30
    ServerAliveCountMax 3

그런 다음 홈 디렉토리에 스크립트를 배치하십시오.외딴byobu 세션을 위해 머신을 설정합니다. "jupyter" 세션이 생성되었는지 테스트하려면 명령 목록이 아닌 스크립트가 필요합니다. 이름을 remote-jupyter-startup.sh로 지정했습니다.

#!/bin/bash
# Test if there's a 'jupyter' session already set up
if [ -z "$(byobu list-sessions | grep jupyter)" ]
    # If not, then set up the session
    then
    # Create a new detached session named 'jupyter'
    byobu new-session -d -s jupyter
    # Pass a 'cd' command to the session, then 'C-m' to execute
    byobu send-keys -t jupyter 'cd ~/Projects' 'C-m'
    # Pass the 'jupyter' command to the session, then 'C-m' to execute
    byobu send-keys -t jupyter 'jupyter notebook --no-browser --port=8889' 'C-m'
    # Create a second window in the session
    byobu new-window -t jupyter:1
fi
# Attach to the session
byobu attach-session -t jupyter

실행 가능하게 만들어라

chmod +x remote-jupyter-startup.sh

지금현지의내가 운전할 수 있는 기계

ssh remote-server-jupyter -t "./remote-jupyter-startup.sh;"

관련 정보