¸®´ª½º ½©½ºÅ©¸³Æ®ÀÇ ÀÌ»óµ¿ÀÛ...Á» ºÁÁÖ¼¼¿ä.

   Á¶È¸ 4500   Ãßõ 0    

저번에 올린 질문에 대해서는해결했는데...
 
이번에는 결과값이 필요없는 부분이 출력된다는 것이 문제입니다.
 
모니터링스크립트인데...
 
모니터링 스크립트 동작개요 : 
 
1번과  2번 두대의 서버가 돌아가고 있는 가운데, 특정 프로세스의 상태값을 확인해서
 
(1) 1번 서버에서의 프로세스 값이 available 및 primary값이면 sh hadr_status0.sh 실행,
 
      이하 스크립트는 실행하지 않고 상태값이 바뀔때까지 모니터링 반복
     
 
(2) 1번 서버에서의 프로세스 값이 available 및 standby값이면 sh hadr_status1.sh 실행
 
       이하 스크립트는 실행하지 않고 상태값이 바뀔때까지 모니터링 반복
 
(3)  1번 서버에서의 프로세스 값이 available 이 아니면 echo hello wolrd 출력 (실제 동작해야 하는 스크립트는 #로 우선 주석처리)
 
      이하 스크립트는 실행하지 않고 상태값이 바뀔때까지 모니터링 반복
 
인데요...
 
 
 
(1)번 조건의 경우 sh hadr_status0.sh 만 실행해서
linuxx86svr0 Primary Peer
linuxx86svr1 Standby Peer
 
위 처럼만 나와야 하는데 실제로 출력되는 값은
 
linuxx86svr0 Primary Peer
linuxx86svr1 Standby Peer
linuxx86svr0
linuxx86svr1
로 (3)번에 해당하는 스크립트 외 (1)번과 (2)번에 해당하는 모든 스크립트가 실행 및 출력
 
 
(2)번 조건의 경우 sh hadr_status1.sh 만 실행해서
linuxx86svr0 Standby Peer
linuxx86svr1 Primary Peer
위 처럼만 나와야 하는데 실제로 출력되는 값은
linuxx86svr0
linuxx86svr1
linuxx86svr0 Standby Peer
linuxx86svr1 Primary Peer
로 (3)번에 해당하는 스크립트 외 (1)번과 (2)번에 해당하는 모든 스크립트가 실행 및 출력
 
 
 
(3)번조건의 경우 hello world만 찍어야 하는데 실제 출력은
linuxx86svr0
linuxx86svr1 Standby RemoteCatchupPending
linuxx86svr0
linuxx86svr1
Hello World!
와 같이 (1) ~ (3)의 모든 스크립트를 실행해버리네요.
 
 
각각의 스크립트를 모두 올리오니...도움바랍니다.
 
일단 메인 스크립트, 즉 sh hadr_status0.sh, sh hadr_status1.sh, hello world를 호출하는 스크립트는
 
hadr_mon.sh 입니다.
 
 
[db2inst1@linuxx86svr1 ~]$ cat hadr_mon.sh
#!/bin/sh
 
while true
 
do
  clear
 
ssh  db2inst1@linuxx86svr0 /db2home/db2inst1/sqllib/bin/db2gcf -i db2inst1 -s | grep DB2 | awk '{ print $4 }' > STATUS0
ssh  db2inst1@linuxx86svr0 db2pd -d sample -hadr | grep Primary | grep -v PrimaryFile | awk '{print $1}' > Role0
     
STATUS2=`cat STATUS0`
 
Role2=`cat Role0`
if  [[ $STATUS2=Available]  &&  [$Role2=Primary ]]
 
    then
   
       sh hadr_status0.sh
elif  [[ $STATUS2=Available]  &&  [$Role2=Standby ]]
   then
     sh hadr_status1.sh
else [ $STATUS2 != 'Available' ]
  then
#     sh hadr_takeover1.sh
#     sh hadr_status1.sh
echo 'Hello World!'
fi
rm -rf Role2 STATUS2 h1 h2
sleep 3
 
done
 
 
[db2inst1@linuxx86svr1 ~]$ cat hadr_status0.sh
#!/bin/sh

ssh db2inst1@linuxx86svr0 hostname > h1
ssh db2inst1@linuxx86svr0 "db2pd -d sample -hadr |  grep Primary |  grep -v PrimaryFile " >> h1
 
hostname > h2
db2pd -d sample -hadr  |  grep Standby | awk '{print $1, $2}' >> h2

echo `cat h1 |  awk '{print $1, $2}'`
echo `cat h2 |  awk '{print $1, $2}'`
 
 
 
 
 
[db2inst1@linuxx86svr1 ~]$ cat hadr_status1.sh
#!/bin/sh

ssh db2inst1@linuxx86svr0 hostname > h1
ssh db2inst1@linuxx86svr0 "db2pd -d sample -hadr  |  grep Standby"  >> h1
echo `cat h1 |  awk '{print $1, $2}'`
hostname > h2
db2pd -d sample -hadr |  grep Primary |  grep -v PrimaryFile  >> h2
echo `cat h2 |  awk '{print $1, $2}'`
 
 
 
hadr_takeover1.sh은 아직 동작하지 않았으니 우선 생략합니다.
 
참고적으로 상태값이 수집되는 로그내용을 함께 올립니다.
이하 로그의 상태는 (1)번에 해당하는 상태에서의 수집되는 조건입니다.
즉, (1)번서버가 available이면서 primary인 상태이고, 2번서버는 standby상태라는 것입니다.
 
 
 
[db2inst1@linuxx86svr1 ~]$ ssh  db2inst1@linuxx86svr0 /db2home/db2inst1/sqllib/bin/db2gcf -i db2inst1 -s
Instance  : db2inst1
DB2 State : Available
 
위 로그값에서 grep 및 awk적용
ssh  db2inst1@linuxx86svr0 /db2home/db2inst1/sqllib/bin/db2gcf -i db2inst1 -s | grep DB2 | awk '{ print $4 }'
 
[db2inst1@linuxx86svr1 ~]$ ssh  db2inst1@linuxx86svr0 /db2home/db2inst1/sqllib/bin/db2gcf -i db2inst1 -s | grep DB2 | awk '{ print $4 }'
Available
 
 
 
1번서버에서 수집되는 내용
[db2inst1@linuxx86svr0 ~]$ db2pd -d sample -hadr
Database Partition 0 -- Database SAMPLE -- Active -- Up 0 days 00:00:07 -- Date 2013-02-18-14.52.39.053005
HADR Information:
Role    State                SyncMode HeartBeatsMissed   LogGapRunAvg (bytes)
Primary Peer                 Sync     0                  0                  
ConnectStatus ConnectTime                           Timeout  
Connected     Mon Feb 18 14:52:36 2013 (1361166756) 120      
LocalHost                                LocalService     
10.100.8.109                             51000            
RemoteHost                               RemoteService      RemoteInstance   
10.100.8.110                             51000              db2inst1         
PrimaryFile  PrimaryPg  PrimaryLSN       
S0000005.LOG 0          0x0000000002710000
StandByFile  StandByPg  StandByLSN       
S0000005.LOG 0          0x0000000002710000
 
 
 
2번서버에서 수집되는 내용
[db2inst1@linuxx86svr1 ~]$ db2pd -d sample -hadr
Database Partition 0 -- Database SAMPLE -- Active -- Up 0 days 03:16:27 -- Date 2013-02-18-14.50.42.648510
HADR Information:
Role    State                SyncMode HeartBeatsMissed   LogGapRunAvg (bytes)
Standby RemoteCatchupPending Sync     0                  0                  
ConnectStatus ConnectTime                           Timeout  
Disconnected  Mon Feb 18 14:33:41 2013 (1361165621) 120      
LocalHost                                LocalService     
10.100.8.110                             51000            
RemoteHost                               RemoteService      RemoteInstance   
10.100.8.109                             51000              db2inst1         
PrimaryFile  PrimaryPg  PrimaryLSN       
S0000005.LOG 0          0x0000000002710000
StandByFile  StandByPg  StandByLSN         StandByRcvBufUsed
S0000005.LOG 0          0x0000000002710000 0% 
 
 
 
 
 
 
ªÀº±Û Àϼö·Ï ½ÅÁßÇÏ°Ô.
¹Ú³²±Ô 2013-02
grep¸í·É¾î¿¡ ´ëÇؼ­ ÇнÀÀÌ ÇÊ¿äÇÒ µí ÇÕ´Ï´Ù..
$man grep Ä¡½Ã¸é grep ¸Å´º¾ó ³ª¿À¸ç, ¾çÀÌ ¾ó¸¶¾ÈµÇ´Ï ±Ý¹æ ÀÐÀ¸½Ç °Ì´Ï´Ù.

±×·³, ÇØ°á¹æ¹ýÀº¿ä....
(1)(2)
hadr_status0.sh hadr_status1.sh¿¡¼­ echo ºÎºÐÀ» ¼öÁ¤ÇÕ´Ï´Ù.
echo `cat h1 |  awk '{print $1, $2}'` ----> echo `cat h1 |  awk '{print $1, $2}' | grep Peer`
echo `cat h2 |  awk '{print $1, $2}'` ----> echo `cat h2 |  awk '{print $1, $2}' | grep Peer`

(3)
ÁÖ¼® # 󸮰¡ µÇÁö ¾Ê¾Ò´Ù¸é
hadr_takeover1.sh ¿¡¼­ echo ºÎºÐÀ» È®ÀÎÇØ¾ß ÇÒ µí ÇÕ´Ï´Ù.
hadr_status1.sh ¿¡¼­µµ echo ºÎºÐÀÌ ÀÖÀ¸¹Ç·Î ´ç¿¬È÷ Ãâ·ÂµÉ °ÍÀÌ°í¿ä..
     
±è°Ç¿ì 2013-02
°¨»çÇÕ´Ï´Ù....


QnA
Á¦¸ñPage 3403/5590
2015-12   1031826   ¹é¸Þ°¡
2014-05   4480368   Á¤ÀºÁØ1
2013-03   4798   ȸ¿øK
2013-03   8488   ÁÖȲº°
2013-03   7789   ¸ð¸¥´Ù°í
2013-03   6217   Larry
2013-03   4871   ¿ì¾Ó»Ñ¾Ó
2013-03   5050   ÀÓÁ¾¿­
2013-03   5151   À嵿°Ç2014
2013-03   12744   º¸¶÷ÀÌ
2013-03   4846   Println
2013-03   13014   2CPU2
2013-03   5642   ¹æoÈ¿o¹®
2013-03   13632   ¼Û½ÂÈ­
2013-03   7791   Ä£ÀýÇÑÄíÅ°¾¾
2013-03   4727   Àª¶ó¸ä
2013-03   7646   ¹«¾Æ
2013-03   5808   TeaRoom
2013-03   8893   ±è°Ç¿ì
2013-03   5544   º´¸ÀÆù
2013-03   5265   ±èµ¿¿­
2013-03   8768   ¸ð¸¥´Ù°í