2017-10-01 1 views
0

누군가 내가 아래의 "메타 새로 고침"을 할 때 알려 주시겠습니까? bash program-run-tmp-directory3.sh &> stdout.out &도 다시 실행 하시겠습니까? 또는 apache을 유지하면서 브라우저 만 새로 고칩니다.메타 새로 고침 (새로 고침 브라우저 만 사용)

"pid"은 백그라운드에서 실행되는 프로그램의 "프로세스 ID"입니다.

아래 코드가 bash program-run-tmp-directory3.sh &> stdout.out & 프로그램을 다시 실행하는 경우. 어떻게 피할 수 있는지 알려주십시오.

#!/bin/sh 
echo "Content-type: text/html" 
echo "" 
bash program-run-tmp-directory3.sh &> stdout.out & 
pid=$! 

if [[ `ps -p $pid | wc -l` -gt 1 ]] 
then 
    output="Program is running. Running time depends on the number of alternatively spliced proteins the submitted gene has. Results will be displayed here." 
    echo "<html>" 
    echo "<head>" 
    echo "<meta http-equiv=\"refresh\" content=\"10\"/>" 
    echo "</head>" 
    echo "<body>" 
    echo "<table width=\"750\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" 
    echo "<tr><td><img src=\"../../images/calc.gif\" align=\"absmiddle\"> <strong> $output </strong></td></tr>" 
    echo "</table>" 
    echo "</body>" 
    echo "</html>" 
fi 

감사합니다.

+0

귀하의 질문에 서식 코드에 더 많은 노력을 넣어주세요. 코드 라인 앞에 12 개가 아닌 4 개의 공백이 필요합니다. –

+0

특정 URL에 대한 요청을받을 때마다이 스크립트를 실행하도록 서버를 구성했다고 가정합니다. 이 경우 예, 해당 URL에 대한 요청이있을 때마다 스크립트가 다시 실행됩니다 ('bash'에 대한 내장 호출 포함). 메타 새로 고침은 브라우저에 10 초마다 페이지를 다시 가져 오도록 요청합니다. 브라우저가 지시한다면,'bash'에게 10 초마다'program-run-tmp-directory3.sh'를 실행할 것을 요청할 것입니다. –

답변

0

이 시점에서, 다른 스크립트가 실행 중이고 다시 작성하는 것을 피하는 방법은 bash 스크립트에서 어떻게 감지되는지입니다. 스크립트의 명령 행에 대한 ps의 출력은 grep의 출력보다 빠르다. 이것은 ps에 사용하는 옵션에 따라 grep 프로세스 명령 줄을 표시 할 수 있으며 이는 분명히 grep 패턴의 일부로 스크립트의 명령 줄을 포함하기 때문에 약간 복잡합니다. 이 문제를 해결하는 여러 가지 방법 중 하나는 here입니다. 이 모든 설명은 실제 스크립트보다 길다.

한 번 더 메모 그냥 당신이 bash$! 수단을 구성 이해 있는지 확인하려면 :

($!) Expands to the process ID of the job most recently placed into 
the background, whether executed as an asynchronous command or using 
the bg builtin (see Job Control Builtins). 

그래서, 즉 만 CGI 스크립트의 현재 실행이 알고있는 것을 참조 할 것입니다. 브라우저가 다시 새로 고침하기로 결정하면 서버에 또 다른 HTTP GET이 전송되어 다시 CGI 스크립트가 생성됩니다. $!은 가장 최근에 생성 된 의 작업 만 스크립트의 인스턴스로 나타냅니다. 난 당신이 뭘 하려는지 직관 경우

, 당신은이 (테스트되지 않은) 같은 것을 할 수 있습니다 :

#!/bin/sh 
echo "Content-type: text/html" 
echo "" 
# if other script not already running 
if ! ps aux | grep "[b]ash.*program-run-tmp-directory3.sh" 
    then 
    bash program-run-tmp-directory3.sh &> stdout.out & 
    # I'm superstitious; let's give it a moment to start 
    sleep 1 
    fi 

if ps aux | grep "[b]ash.*program-run-tmp-directory3.sh" 
then 
    output="Program is running. Running time depends on the number of alternatively spliced proteins the submitted gene has. Results will be displayed here." 
    echo "<html>" 
    echo "<head>" 
    echo "<meta http-equiv=\"refresh\" content=\"10\"/>" 
    echo "</head>" 
    echo "<body>" 
    echo "<table width=\"750\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" 
    echo "<tr><td><img src=\"../../images/calc.gif\" align=\"absmiddle\"> <strong> $output </strong></td></tr>" 
    echo "</table>" 
    echo "</body>" 
    echo "</html>" 
else 
    : # ... some useful error output composed as HTML 
fi 
관련 문제