2011-08-06 62 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