제가 원하는 결과는...다음과 같은데요...
------------------------------------------------
DATE | NAME | STATUS |
------------------------------------------------
2009-07-08-22:12:07:08| TS_TEMP_16K | 0x0000 |
2009-07-08-22:12:07:08| TS_DBA_D00 | 0x0000 |
2009-07-08-22:12:07:08| TS_TEMP_32K | 0x0000 |
2009-07-08-22:12:07:08|TS_ENTMT_D00 | 0x0000 |
2009-07-08-22:12:07:08|TS_ENTMT_I00 | 0x0000 |
2009-07-08-22:12:07:08| TS_QP_D | 0x0000 |
2009-07-08-22:12:07:08| TS_OCMT_D01 | 0x0000 |
2009-07-08-22:12:07:08| TS_OCMT_I01 | 0x0000 |
2009-07-08-22:12:07:08| TS_TEST_D00 | 0x0000 |
2009-07-08-22:12:07:08|_MANAGE_D00 | 0x0000 |
------------------------------------------------
제가 만든 스크립트가 잘못되어...다음과 같이 나오네요.
=============================================================
2009-07-08:22:12:20 | TS_TEMP_16K |
TS_DBA_D00 | |
TS_TEMP_32K | |
TS_ENTMT_D00 | |
TS_ENTMT_I00 | |
TS_QP_D | |
TS_OCMT_D01 | |
TS_OCMT_I01 | |
TS_TEST_D00 | |
TS_MANAGE_D00 | 0x0000 |
0x0000 | |
0x0000 | |
0x0000 | |
0x0000 | |
0x0000 | |
0x0000 | |
0x0000 | |
0x0000 | |
제가 만든 소스는 다음과 같습니다만...
SNUM=1
while true
do
#----------------------------------
if [ "${SNUM}" -eq 1 ];then
cat << HEAD1 >> \n
DATE | NAME | STATUS |
HEAD1
fi
#----------------------------------
DATE=`date +%Y-%m-%d:%H:%M:%S`
GETSNAP_TBS=`db2 list tablespaces`
NAME= `echo "$GETSNAP_TBS" |grep "Name" |cut -d= -f2 |awk '{print $1}'`
STATUS=`echo "$GETSNAP_TBS" |grep "State" |cut -d= -f2 |awk '{print $1}'`
RDATA="$DATE $NAME $STATUS"
echo "$RDATA" |awk '{printf "%20s | %15s | %10s|\n", $1, $2, $3}'
sleep 3
done
어디가 잘못된건가요?
참고적으로 상기한 스크립트가 항목을 가져오는 원본화일의 내용은 다음과 같습니다.
Tablespace ID = 1
Name = TS_TEMP_16K
Type = Database managed space
Contents = System Temporary data
State = 0x0000
Detailed explanation:
Normal
Tablespace ID = 7
Name = TS_DBA_D00
Type = Database managed space
Contents = All permanent data. Large table space.
State = 0x0000
Detailed explanation:
Normal
Tablespace ID = 12
Name = TS_TEMP_32K
Type = Database managed space
Contents = System Temporary data
State = 0x0000
Detailed explanation:
Normal
Tablespace ID = 34
Name = TS_ENTMT_D00
Type = Database managed space
Contents = All permanent data. Large table space.
State = 0x0000
Detailed explanation:
Normal
Tablespace ID = 35
Name = TS_ENTMT_I00
Type = Database managed space
Contents = All permanent data. Large table space.
State = 0x0000
Detailed explanation:
Normal
Tablespace ID = 44
Name = TS_QP_D
Type = Database managed space
Contents = All permanent data. Large table space.
State = 0x0000
Detailed explanation:
Normal
Tablespace ID = 48
Name = TS_OCMT_D01
Type = Database managed space
Contents = All permanent data. Large table space.
State = 0x0000
Detailed explanation:
Normal
Tablespace ID = 49
Name = TS_OCMT_I01
Type = Database managed space
Contents = All permanent data. Large table space.
State = 0x0000
Detailed explanation:
Normal
Tablespace ID = 50
Name = TS_TEST_D00
Type = Database managed space
Contents = All permanent data. Large table space.
State = 0x0000
Detailed explanation:
Normal
Tablespace ID = 57
Name = TS_MANAGE_D00
Type = Database managed space
Contents = All permanent data. Large table space.
State = 0x0000
Detailed explanation:
Normal
DB21011I In a partitioned database server environment, only the table spaces
on the current node are listed.
GETSNAP_TBS="list"
count=`cat "$GETSNAP_TBS" | grep "Name" | cut -d= -f2 | gawk '{print $1}' | paste -s`
cnt=`cat "$GETSNAP_TBS" | grep "Name" | cut -d= -f2 | gawk '{print $1}' | wc -l`
echo "------------------------------------------------------"
echo " DATE | NAME | STATUS "
echo "------------------------------------------------------"
for i in `echo $count`
do
DATE=`date +%Y-%m-%d:%H:%M:%S`
NAME=`cat "$GETSNAP_TBS" | grep "Name" | cut -d= -f2 | gawk '{print $1}' | tail -n"$cnt" | head -n1`
STATUS=`cat "$GETSNAP_TBS" | grep "State" | cut -d= -f2 | gawk '{print $1}' | tail -n"$cnt" | head -n1`
RDATA="$DATE $NAME $STATUS"
echo "$RDATA" | gawk '{printf "%20s | %14s | %10s \n", $1, $2, $3}'
sleep 1
cnt=`expr $cnt - 1`
done
테스트한 결과...기대한 결과가 나오지 않았습니다.
일단은...
적어주신 list라는 것은 제가 올려드린 예제(소스)를
list라는 화일로 만든 후 이 화일을 이용하여 내용을
필터링 하는것인데...그렇다 하더라도...
다음과 같이 결과가 나옵니다.
# sh tbschk.sh
Usage: paste [-s] [-d List] File...
tbschk.sh[3]: gawk: not found.
tbschk.sh[4]: gawk: not found.
------------------------------------------------------
DATE | NAME | STATUS
------------------------------------------------------
또한...gwak를 awk로 바꾸고 했는데도...
다음과 같은 결과가 나옵니다...
# sh tbschk.sh
Usage: paste [-s] [-d List] File...
------------------------------------------------------
DATE | Name | STATUS
------------------------------------------------------
질문 내용과 comment의 스크립트를 비교/연구하는 것이 좋을 듯 합니다.
제가 작성한것은 리눅스의 bash_shell에서 테스트를 한것 입니다.
DB2를 사용하시는 것을 보니 AIX 같은데 다시한번 해봐야 할것 같네요.
즉, $count와 $cnt의 값을 확인 하시고, NAME과 STATUS 의 tail 값이 뭐가 나오는지 확인하시면 원하는 결과가 나오리라 생각 됩니다.
나머지 스크립트들은 비슷한 것 같네요.
gawk, awk 들은 상관없네요.