my script:
#!/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
The process is :
- login into database to execute a procedure "prc_auto_restart"
- the procedure will output the
/wasdata/scripts/systeminf/tmp-was-restart.sh
- execute the
/wasdata/scripts/systeminf/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]$
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
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!!!