2011-08-06 3 views
0

내 스크립트 :nohup을 사용하여 명령을 혼동하면 안 되니?

#!/bin/bash 
. /home/was/.bash_profile 
export PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/was/bin:/wasdata/oracle/10.2.0/client_1/bin: 

    sqlplus "mon_system/[email protected]" <<eof 
    set echo off 
    set feedback off 
    set serveroutput on 
    set term off 
    set sqlprompt "" 
    set linesize 200 
    spool /wasdata/scripts/systeminf/tmp-was-restart.sh 
    exec prc_auto_restart 
eof 
    sed -i '/prc_auto_restart/d' tmp-was-restart.sh 
    /wasdata/scripts/systeminf/tmp-was-restart.sh 
    cat /dev/null>/wasdata/scripts/systeminf/tmp-was-restart.sh 

과정은 다음과 같습니다 데이터베이스에 1 로그인 절차 "prc_auto_restart" 2 프로 시저를 실행하기 위해 출력합니다 "/wasdata/scripts/systeminf/tmp-was-restart.sh 제가

SCRI 실행할 때
ssh [email protected] "ps -ef|grep was1.*WebSphere.*c01_ship_s01|grep -v "grep">>kill.log;ps -ef|grep was1.*WebSphere.*c01_ship 
_s01|grep -v "grep"|awk '{print \"kill -9 \" \$2}'|sh" 

값 : tmp-was-restart.sh 원하는 것

"/wasdata/scripts/systeminf/tmp-was-restart.sh" 3 실행 " 그것은, 그것은 두 개의 쉘을 포크 것

[[email protected] systeminf]$ nohup prod-auto-restart.sh & 
[1] 29983 
[[email protected] systeminf]$ nohup: appending output to `nohup.out' 


[1]+ Stopped     nohup prod-auto-restart.sh 
[[email protected] systeminf]$ 
[[email protected] systeminf]$ 
[[email protected] systeminf]$ ps -ef|grep autp 
was  30014 27492 0 16:33 pts/4 00:00:00 grep autp 
[[email protected] systeminf]$ ps -ef|grep auto 
was  29983 27492 0 16:33 pts/4 00:00:00 /bin/bash prod-auto-restart.sh 
was  30003 29983 0 16:33 pts/4 00:00:00 /bin/bash prod-auto-restart.sh 
was  30021 27492 0 16:33 pts/4 00:00:00 grep auto 

, 그리고 나는 tmp-was-restart.sh을 확인하십시오

[[email protected] systeminf]$ ./prod-auto-restart.sh 

SQL*Plus: Release 10.2.0.1.0 - Production on Sat Aug 6 16:33:08 2011 

Copyright (c) 1982, 2005, Oracle. All rights reserved. 


Connected to: 
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production 
With the Partitioning, Real Application Clusters, OLAP and Data Mining options 

SQL> SQL> SQL> SQL> SQL> ssh -t -t [email protected] "ps -ef|grep was1.*WebSphere.*c01_ship_s01|grep -v "grep">>kill.log;ps -ef|grep was1.*WebSphere.*c01_ship_s01|grep -v "grep"|awk '{print \"kill -9 \" \$2}'|sh" 
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production 
With the Partitioning, Real Application Clusters, OLAP and Data Mining options 
Connection to 10.10.4.212 closed. 
[[email protected] systeminf]$ 

을하지만 난 스크립트를 실행 nohup을 사용하는 경우 : PT 직접 스크립트가 작동 올바른지, 그리고"sed -i '/ prc_auto_restart/d'tmp-was-restart.sh"명령이 올바르게 실행되고 "/wasdata/scripts/systeminf/tmp-was-restart.sh" , 나는/프로세스를 29983, "/wasdata/scripts/systeminf/tmp-was-restart.sh"명령이 실행되지만, "cat/dev/null> wasdata/scripts/systeminf/tmp-was-restart.sh "아닙니다 execu 매우 혼란스러운 ted!

+0

누구든지이 사실을 알고 있습니까? – koko

답변

0

Stopped 메시지의 가장 일반적인 이유는 스크립트가 명령 줄을 통해 사용자 입력을 기다리고 있다는 것입니다. 일반적으로 read 명령입니다. 내가 게시 한 코드에는 아무 것도 표시되지 않으므로 보이지 않는 자식 스크립트가 있으면 read을 확인하십시오. 스크립트가 'Ctrl-S'(정지) 문자를 받았다는 가능성이 훨씬 적습니다. 신호.

sqlplus의 사용법은 정확하지만 어떤 이론을 테스트하기 위해 sqlplus에 액세스 할 수 없으므로 sqlplus의 cmd-line 사용법에 대한 설명서를 두 번 확인하십시오. 아마도 -n 옵션 (또는 기타)을 나타낼 수 있습니다 'no cmd-line interaction'.

마지막으로 쉘 디버깅 모드가 도움이 될 수 있습니다.

시도하십시오 PS4='$LINENO>'; set -vx 스크립트 맨 위에 있습니다. 출력을 읽는 방법을 이해하는 데는 약간의 학습이 필요합니다. -v 옵션을 사용하면 if .. ; then ; ... else ; ... fi ,, 또는 while ... done 또는 하나의 파이프 라인 만 평가되는 코드 블록을 표시 할 수 있습니다.

이 정보가 도움이되기를 바랍니다.

P. 당신이 새로운 사용자로 보일 때, 당신이 그것을 받아 들일 수있는 것으로 표시하고/또는 유용한 답으로 + (또는 -)를주는 것을 기억하는 데 도움이되는 대답을 얻으면.

+0

Hi shelter, 답장을 보내 주셔서 감사합니다.하지만 아무 것도 없습니다 – koko

+0

주 스크립트 또는 작성한 스크립트에서 가장 혼란스러운 것은 그 명령이 직접 실행될 때 왜 작동합니까? – koko

+0

안녕하세요 셸터, 나는 당신이 스크립트를 디버깅하기 위해 언급 한 명령을 사용합니다, 마침내 여기 멈췄습니다 : 18> sed -i/prc_auto_restart/d tmp-was-restart.sh /wasdata/scripts/systeminf/tmp-was- restart.sh 19 /wasdata/scripts/systeminf/tmp-was-restart.sh tcsetattr : 입/출력 오류 – koko

관련 문제