2016-06-22 5 views
1

현재이 프로그램이 열려 있지 않을 때마다 자동으로 프로그램을 부팅해야하는 프로그램을 작성 중입니다. 부팅하려면 수퍼 유저 권한이 필요합니다. 현재, 나는 다음과 같이보고, 작업 배쉬 스크립트가 :Bash 스크립트 다중 명령 문제

#!/bin/bash 

while true; do #Continue indefinitely 

    if [ $(ps aux | grep '/odroid_detection' | grep -v '<defunct>' -c) -le 4 ]; then #if less than 3 odroid_servers are active (booter opens 3 processes) 
     xterm -iconic -e su -c "xterm -iconic -hold /home/odroid/Documents/SUNRISE-Odroid/_odroid_detection/_odroid_detection/bin/Debug/_odroid_detection" 
    fi 

    sleep 60 #check every minute 

done 

그러나,이 루트 맵 대신은에있는지도에서 실행되기 때문에 계획대로 정확하게 작동하지 않는 경우, 실행 프로그램. 따라서 실행 파일이 맵 (~/Documents/SUNRISE-Odroid/_odroid_detection/_odroid_detection/bin/Debug)에 있지만 위에서 언급 한 것과 동일한 기능을가집니다.

: 그것은 터미널에서 다음과 같은 오류를 제공합니다 .. 이것은 그러나, 작동하지 않습니다

#!/bin/bash 

while true; do #Continue indefinitely 

    if [ $(ps aux | grep '/odroid_detection' | grep -v '<defunct>' -c) -le 4 ]; then #if less than 3 odroid_servers are active (booter opens 3 processes) 
     xterm -iconic -e "cd ../_odroid_detection/_odroid_detection/bin/Debug/ && su -c "xterm -iconic -hold -e _odroid_detection"" 
    fi 

    sleep 60 #check every minute 

done 

, 나는 많은 대안을 시도했지만 내가이 작업을 얻이 수없는 것 : 이것은 내가 생각 해낸 것입니다

xterm: Can't execvp cd ../_odroid_detection/_odroid_detection/bin/Debug && su -c xterm: No such file or directory 

이 오류를주는 xterm은 ~/Documents/SUNRISE-Odroid/Bash에서 열리고 위에서 언급 한 cd를 실행하면 별도로 실행하면 작동하지 않으므로 파일을 찾을 수없는 이유를 이해할 수 없거나 예배 규칙서.

제안 사항?

+2

bash- 질문과 관련이 없습니다. 이에 대해 [감독자] (http://supervisord.org/)를 사용해 보셨습니까? 이는 관리자가하는 것과 정확히 같은 유형입니다. 'numprocs' 설정을 통해 X 프로세스의 수를 유지하십시오. – Dencker

+0

'man xterm'에 설명되어 있듯이,'-e'는 프로그램과 그 인수를 매개 변수로 취하고 명령리스트는 아닙니다. 하지만 프로그램으로'bash'를 실행할 수는 있습니다. – choroba

+0

좋아요, StackOverflow의 색칠은 내가 한 실수를 이해하게 만들었습니다. 'su -c'다음의 시작 인용문은 xterm 실행 행의 끝 인용구로 해석됩니다. 이제는 작업 프로그램을 가지고 해결책을 조금 게시 할 것입니다. – Timmeh

답변

0

StackOverflow의 색칠로 인해 내가 한 실수를 이해하게되었습니다. 'su -c'다음의 시작 인용 부호는 xterm 실행 행의 종료 인용구로 해석됩니다. 작업 코드는 다음과 같습니다 :

#!/bin/bash 

while true; do #Continue indefinitely 

    if [ $(ps aux | grep '/odroid_detection' | grep -v '<defunct>' -c) -le 2 ]; then #if less than 3 odroid_servers are active (booter opens 3 processes) 
     xterm -iconic -e "cd ../_odroid_detection/_odroid_detection/bin/Debug/ && su -c ./_odroid_detection" 
    fi 

    sleep 60 #check every minute 

done