x를 시작하고 SSH를 통해 원격으로 스크립트를 실행하려면 어떻게 해야 합니까?

x를 시작하고 SSH를 통해 원격으로 스크립트를 실행하려면 어떻게 해야 합니까?

X를 시작하고 그래픽 프로그램을 시작하는 다음 스크립트가 있습니다.

#!/bin/sh
#startGraphics.sh 
#Starts X and runs the graphics program

xinit /opt/common/graphics/bin/launchGraphics.sh &
sleep 10 ; 
echo "Successfully launched graphics program!"

스크립트를 실행하면 SSH 세션이 닫히자마자 X와 그래픽 프로그램이 종료되기 때문에 절전 모드와 에코를 추가했습니다. 문제는 절전 및 에코로 인해 X 및 그래픽 프로그램이 시작되지만 SSH 세션이 종료되지 않는다는 것입니다.

하지만,머신에 수동으로 SSH를 연결하고 startGraphics.sh 스크립트를 실행한 다음 X 서버와 프로그램이 시작된 후 SSH 세션을 종료하면 계속 실행되고 SSH 세션이 중단되지 않습니다.

내가 여기서 뭘 잘못하고 있는 걸까? 내가 하려는 작업을 수행하는 올바른 방법은 무엇입니까? 즉, 그래픽 프로그램을 사용하여 원격으로 X를 시작하고 X를 즉시 종료하지 않고 중단 없이 SSH 세션을 완료하는 방법은 무엇입니까?

질문과 관련이 없다고 생각하지만, 만일을 대비해 launchGraphics.sh 스크립트가 있습니다.

#!/bin/sh
#launchGraphics.sh
#Starts the graphics program. Requires X to be running
xrandr -s 1920x1050 ;
/opt/common/graphics/bin/graphics --position 0,0 --mode 1 &
/opt/common/graphics/bin/graphics --position 100,0 --mode 2 &
/opt/common/graphics/bin/graphics --position 300,0 --mode 3 

답변1

문제는 stdout(및 아마도 stderr)의 리디렉션으로 밝혀졌습니다.

xinit 줄 끝에 > logfile.log 2>&1 & 를 추가하면 SSH 세션이 안전하게 닫히고 X 세션과 그래픽 프로그램이 계속 실행됩니다.

따라서 최종 startGraphics.sh는 다음과 같습니다.

#!/bin/sh
#startGraphics.sh 
#Starts X and runs the graphics program

xinit /opt/common/graphics/bin/launchGraphics.sh > /dev/null 2>&1 &
sleep 10 ; 
echo "Successfully launched graphics program!"

관련 정보