使用 nohup 执行命令很困惑? [英] Using nohup to execute command very confused?
问题描述
我的脚本:
#!/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/monsystem@10.10.4.90" <<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
过程是:
- 登录数据库执行程序prc_auto_restart"
- 该过程将输出
/wasdata/scripts/systeminf/tmp-was-restart.sh
- 执行
/wasdata/scripts/systeminf/tmp-was-restart.sh
tmp-was-restart.sh 会喜欢:
the tmp-was-restart.sh will like:
ssh was1@10.10.4.212 "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"
当我直接执行脚本时,脚本有效:
When i execute the script directly, the script works :
[was@web-tkt2-01 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 was1@10.10.4.212 "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.
[was@web-tkt2-01 systeminf]$
但是当我使用 nohup 执行脚本时:
But when i use nohup to execute the script:
[was@web-tkt2-01 systeminf]$ nohup prod-auto-restart.sh &
[1] 29983
[was@web-tkt2-01 systeminf]$ nohup: appending output to `nohup.out'
[1]+ Stopped nohup prod-auto-restart.sh
[was@web-tkt2-01 systeminf]$
[was@web-tkt2-01 systeminf]$
[was@web-tkt2-01 systeminf]$ ps -ef|grep autp
was 30014 27492 0 16:33 pts/4 00:00:00 grep autp
[was@web-tkt2-01 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
它会 fork 两个 shell,我检查了 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
没有执行,很迷茫!!!
It will fork two shell, and i check the tmp-was-restart.sh, it was correct, and that mean
the command sed -i '/prc_auto_restart/d' tmp-was-restart.sh
execute correct,and it stoped at /wasdata/scripts/systeminf/tmp-was-restart.sh
, I alse try source/execute method, both not work, after i kill the process 29983 ,the command /wasdata/scripts/systeminf/tmp-was-restart.sh
executed, but the cat /dev/null>/wasdata/scripts/systeminf/tmp-was-restart.sh
not executed, very confused!!!
推荐答案
Stopped
消息的最常见原因是脚本期望用户通过命令行输入,通常是 <代码>读取代码>命令.我在您发布的代码中没有看到任何内容,因此如果有任何不可见的子脚本,请检查read
.脚本收到Ctrl-S"(停止)字符或 ?信号.
The most common reason for the Stopped
message is that the script is expecting input from the user via the command line, usually a read
command. I don't see any in the code you posted, so if there are any child scripts not visible, check there for read
. Much less likely is that the script has received a 'Ctrl-S' (stop) character or ? Signal.
您对 sqlplus 的使用看起来是正确的,但我无法访问 sqlplus 来测试任何理论,因此请仔细检查 sqlplus 的 cmd-line 用法文档,也许有一个 -n
选项(或其他)表示无 cmd-line 交互".
Your usage of sqlplus looks correct, but I don't have access to sqlplus to test any theories, so double check the documentation for cmd-line usage of sqlplus, maybe there a an -n
option (OR other) to indicate 'no cmd-line interaction' .
最后,也许 shell 调试模式可以帮到你.
Finally, maybe shell debugging mode can help you.
试试PS4='$LINENO>';在脚本顶部附近设置 -vx
.弄清楚如何读取输出需要一些学习.-v
选项显示正在评估的代码块,或者是 if .. ;然后 ;... 别的 ;... fi
,或 while ... done
或只是一个管道.
Try PS4='$LINENO>'; set -vx
near top of script. It takes a little learning to figure out how to read the output. The -v
options displays block of code being evaluated, either an if .. ; then ; ... else ; ... fi
,, or while ... done
or just a single pipeline.
我希望这会有所帮助.
附言由于您似乎是新用户,如果您得到的答案对您有帮助,请记住将其标记为已接受,和/或给它一个 +(或 -)作为有用的答案.
P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.
这篇关于使用 nohup 执行命令很困惑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!