소소한 일상에서 책읽기 중

쉘 스크립트로 쉘 실행 및 kill하기 본문

DB까다롭다

쉘 스크립트로 쉘 실행 및 kill하기

다솜여우 2012. 6. 19. 11:30

실행중인 PID를 찾아서 kill한 뒤, 파일을 옮기고 permission을 주고, 다시 nohup으로 쉘을 실행하는 일련의 작업을 쉘 스크립트로 작성하였다..

아직까지는 잘 되다... 다행이다!!

그러나 " ps -ef " 로 조회된 컬럼들의 내용을 모르니 걍 찍었다...

 

===============================================

#!/usr/bin/ksh
#
#  No comment(#) after shell path(#!)
#
#/usr/bin/ksh  # Korn Shell on AIX, HP-UX
#/bin/sh       # POSIX Shell on HP-UX
#/usr/bin/sh   # Bourn Shell on AIX, POSIX Shell on HP-UX
#/usr/bin/csh  # C Shell on HP-UX, AIX
#

v_YYYYMMDD=20100701

# assign(allocate) arguments to variables
if (( $# == 1 )) then
  v_YYYYMMDD=$1
#  v_YYYYMM=$1
fi

export ORACLE_SID=idba1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin:$GI_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:$ORACLE_HOME/OPatch:/u01/app/oracle/product/11.2.0/dbhome_1/jdk/bin:.
export NLS_LANG=AMERICAN_AMERICA.KO16KSC5601
#export NLS_LANG=American_America.KO16MSWIN949
export TNS_ADMIN=$ORACLE_HOME/network/admin

v_LogonUser=scott/tiger

v_ExecDir=/root
v_LogDir=${v_ExecDir}

v_YYYYMMDDNext=`sqlplus -s ${v_LogonUser} << EOF
SET HEADING OFF
SET PAGESIZE 0
SET LINESIZE 8
SET FEEDBACK OFF
SET TERMOUT OFF
SELECT TO_CHAR(TO_DATE('${v_YYYYMMDD}', 'YYYYMMDD')+1, 'YYYYMMDD')
FROM dual
;
exit
EOF`


DATE=`date +"%Y%m%d"`
DATE_1=`expr $DATE - 1`
DATE_2=`expr $DATE - 2`
DATE_SEC=`date +"%Y%m%d%H"`

YYYY=`date +"%Y"`
MM=`date +"%m"`
DD=`date +"%d"`

v_PID=`ps -ef | grep sar.sh | grep -v grep |awk  '{print $1, $2, $3, $4, $5, $6,$7}' |  awk '{print "x"$1, $2, $3, $4"x"}' | grep -v 0x | awk '{print $2}'`

echo ${v_PID}
echo ${DATE}
echo ${DATE_1}

echo cd /root

cd /root

echo kill -9 $v_PID
kill -9 $v_PID

echo ls /root/sar_log_$DATE_1*

ls /root/sar_log_$DATE_1*

echo mv /root/sar_log_$DATE_1* /IF_DATA1/DB_SAR_LOG/

mv /root/sar_log_$DATE_1* /IF_DATA1/DB_SAR_LOG/


echo cd /IF_DATA1/DB_SAR_LOG/

cd /IF_DATA1/DB_SAR_LOG/

echo cp /IF_DATA1/DB_SAR_LOG/sar_log_$DATE_1* /IF_DATA1/DB_SAR_LOG/sar_logs

cp /IF_DATA1/DB_SAR_LOG/sar_log_$DATE_1* /IF_DATA1/DB_SAR_LOG/sar_logs

echo chmod 777 /IF_DATA1/DB_SAR_LOG/sar_logs

chmod 777 /IF_DATA1/DB_SAR_LOG/sar_logs

echo ls -al /root/sar_log_$DATE_1*

ls -al /root/sar_log_$DATE_1*

echo ls -al /IF_DATA1/DB_SAR_LOG/sar_logs

ls -al /IF_DATA1/DB_SAR_LOG/sar_logs

echo cd /root

cd /root

echo sleep 20

sleep 20

echo nohup sar.sh 10 100000 > sar_log_$DATE.log&

nohup sar.sh 10 100000 > sar_log_$DATE.log&