2011-08-06 66 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 「 3執行 」/wasdata/scripts/systeminf/tmp-was-restart.sh「

的tmp-was-restart.sh會喜歡:

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" 

當我執行SCRI PT直接的腳本工作:

[[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執行腳本:

[[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,它是正確的,這意味着 命令「sed -i'/ prc_auto_restart/d'tmp-was-restart.sh」執行正確,並且它停在「/wasdata/scripts/systeminf/tmp-was-restart.sh」 ,我試着執行source/execute方法,兩者都不起作用,在我終止進程29983後,執行了「/wasdata/scripts/systeminf/tmp-was-restart.sh」命令,但是「cat/dev/null>/wasdata/scripts/systeminf/tmp-was-restart.sh「不能執行特德,非常困惑!

+0

任何人都知道放棄這一點? – koko

回答

0

Stopped消息的最常見原因是該腳本需要通過命令行輸入用戶名,通常是read命令。我在您發佈的代碼中沒有看到任何內容,因此如果有任何子腳本不可見,請在此處查詢read。腳本收到'Ctrl-S'(停止)字符或?信號。

您對sqlplus的使用看起來是正確的,但我無法訪問sqlplus來測試任何理論,因此仔細檢查sqlplus的cmd行用法的文檔,可能有-n選項(或其他)來指示'沒有命令行互動'。

最後,也許shell調試模式可以幫助你。

嘗試PS4='$LINENO>'; set -vx靠近腳本的頂部。花費一點時間學習如何讀取輸出。 -v選項顯示正在評估的代碼塊,可能是if .. ; then ; ... else ; ... fi ,,或while ... done或只是一個管道。

我希望這會有所幫助。

P.S.因爲你似乎是一個新用戶,如果你得到一個可以幫助你的答案,請記住將它標記爲已接受,並且/或者給它一個+(或 - )作爲有用的答案。

+0

嗨貝特,謝謝你的回答。但是 – koko

+0

沒有讀命令,無論是主腳本還是它創建的腳本,最困惑的是爲什麼它直接執行命令時工作? – koko

+0

嗨shellter,我使用你提到的命令調試腳本,最後,它停在這裏: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