2014-04-18

slp_srvreg issue

透過TSM進行AIX OS[註1]備份時, 會出現一筆有關slp_srvreg無法寫入的警告訊息, 解決的方法大致上有三種:
第一種:fix這個apar
第二種:關閉slp_srvreg的服務
第三種:TSM進行備份時, 排除該檔案的備份

[註1]AIX OS版本:7.1 TL1 SP5

以下是選擇第二種方法進行處理, 步驟如下:
step1: 寫一支小script, vi /etc/rc.local
###############################################
#!/bin/sh

/usr/bin/ps -ef | grep -v grep | grep slp_srvreg > /dev/null

if [ $? -eq 0 ]; then
   /usr/sbin/slp_srvreg -k
fi

exit 0
###############################################

step2: chmod 700 /etc/rc.local

step3: 在/etc/inittab新增一行 rc.local:2:once:/etc/rc.local > /dev/console 2>&1

2014-03-24

動態調整LPAR資源

動態調整LPAR資源時要注意CPU和Memory的Assign數值不能超過Maximum的數值。


另外若LPAR的RMC連線有問題時, 進行動態調整資源時需要重新啟用LPAR方能生效;問題的檢查方式如下:

As root on the HMC or IVM server, you can execute the rmcdomainstatus command as follows:

# /usr/sbin/rsct/bin/rmcdomainstatus -s ctrmc

You should get a list of all the partitions that the HMC or IVM server can reach on the public network on port 657. The output should look like this:

Management Domain Status: Managed Nodes
  O a  0xc8bc2c9647c1cef3  0003  9.2.5.241
  I a  0x96586cb4b5fc641c  0002  9.2.5.33
  S S  0x5c88fb81dad9f609  0001  9.2.5.65

If you run the rmcdomainstatus command on a Managed Node (i.e. a partition), a list similar to the following should be displayed.

Management Domain Status: Management Control Points
   I A  0xef889c809d9617c7 0001  9.57.24.139

Each line of output represents the status of a cluster node, relative to the node upon which the command is executed.

I. The first token of the node status line is either S, I, i, O, X, or Z.

S

Indicates the line is the status of a peer node itself (when run on IVM, this will indicate the IVM partition itself.
I

Indicates that the partition is “Up" as determined by the RMC heartbeat mechanism (i.e. an active RMC connection exists).
i

Indicates that the partition is Pending Up. Communication has been established, but the initial handshake between two RMC daemons has not been completed. If this indicator is present upon successive executions of the rmcdomainstatus command, then message authentication is most likely failing. Authentication problems will occur when the MCP or partition identity do not match each other’s trusted host list. To list the current identity or identities for the IVM server or HMC and the logical partition run the following command on both:
/usr/sbin/rsct/bin/ctsvhbal
To list the trusted host list on the MCP or partition run :
/usr/sbin/rsct/bin/ctsthl -l
On the IVM or HMC, there is an entry for the partition. On the partition, there is an entry for the IVM or HMC. The HOST_IDENTITY value must match one of the identities listed in the respective ctsvhbal command output.
O

Indicates that the RMC connection is “Down", as determined by the RMC heartbeat mechanism. The partition is either not active or it may also indicate that the RMC daemon on the specified node is not connecting properly. Ensure that the partition can communicate with the HMC or IVM server on the public network and that port 657 is not being blocked on the public network firewall.
X

Indicates that a communication problem has been discovered and the RMC daemon has suspended communications with the RMC daemon that is on the specified node. This is typically the result of a configuration problem in the network, such that small heartbeat packets can be exchanged between the RMC daemon and the RMC daemon that is on the specified node, but larger data packets cannot. This is usually the result of a difference in MTU sizes in the network adapters of the nodes.
Z

Indicates that the RMC daemon has suspended communications with the RMC daemon that is on the specified node because the up/down state of the node is changing too rapidly. This is typically the result of more than one node having the same node ID. (See part III. for instructions on correcting.)
II. The second token of the node status line is either S, A, R, a, or r.

S

Indicates the line is the status of a peer node itself (when run on IVM, this will indicate the IVM partition itself.
A

Indicates that there are no messages queued to the specified node.
R

Indicates that messages are queued to the specified node. This may be caused by a network that is operating under a heavy load or possible a full /var filesystem.
a

Has the same meaning as A, but the specified node is executing a version of the RMC daemon that is at a lower code level than the local RMC daemon.
r

Has the same meaning as R, but the specified node is executing a version of the RMC daemon that is at a lower code level than the local RMC daemon.
III. The third token of the status line is the ID of the specified node.

The node ID is a 64-bit number that is created when RSCT is installed. It is derived using a True Random Number Generator and is used to uniquely identify a node to the RMC subsystem. The node ID is maintained in the /var/ct/cfg/ct_node_id file. A backup copy is maintained in the /etc/ct_node_id file. If this value is not unique among all systems where RSCT is installed and managed by the same HMC or IVM server, you can generate a new cluster identifier with the following command.
/usr/sbin/rsct/install/bin/recfgct
Note: This command will affect any cluster software that uses RSCT such as CSM or GPFS.
IV.The fourth token of the status line is an internal node number that is used by the RMC daemon.

V. If the list is a list of Peer Nodes or Managed Nodes, the fifth token is the name of the node as known to the RMC subsystem.

On power5 and power6 partitions, the RMC connection will be IP based so this will list the IP address of the partition.

2014-03-11

ent0, en0 和 et0的差異

ent0:

The notation ent0 is used to specify the hardware adapter. It has nothing to do with the TCP/IP address. The parameters associated with ent0 can be seen as below:

# lsattr -El ent0

It will show parameters related to card.

It shows adapter_names, alt_addr, auto_recovery, backup_adapter, hash_mode, mode, netaddr, noloss_failover, num_retries, retry_time, use_alt_addr, use_jumbo_frame.

------------------------------------------------------------------------------------------------------------

en0:

en0 represents the interface associated with hardware adapter ent0. The notation en0 is used for Standard Ethernet(inet). The TCP/IP address is associated with this interface.

The parameters associated with en0 can be seen as below:

#lsattr -El en0

It shows all the parameters related with the interface en0 of the adapter ent0.

It shows alias4, alias6, arp, authority, broadcast=1500, mtu, netaddr, netaddr6, netmask, prefixlen, remmtu, rfc1323, security, state, tcp_mssdflt, tcp_nodelay, tcp_recvspace, tcp_sendspace.

Rest everything is same except mtu(Maximum Transfer Unit) value. Which is 1500 as per the standard ethernet protocol.

------------------------------------------------------------------------------------------------------------

et0:

et0 represents the interface associated with hardware adapter ent0. The notation et0 is used for IEEE 802.3 Ethernet(inet). If you are using standard ethernet protocol then it will not have TCP/IP address.

The parameters associated with et0 can be seen as below:

#lsattr -El et0

It shows all the parameters related with the interface et0 of the adapter ent0.

It shows alias4, alias6, arp, authority, broadcast, mtu=1492, netaddr, netaddr6, netmask, prefixlen, remmtu, rfc1323, security, state, tcp_mssdflt, tcp_nodelay, tcp_recvspace, tcp_sendspace.

Note here as well that the MTU shown will be 1492 as per IEEE 802.3 standard. Rest all parameters will be same. Also, netaddr, netmask fields will be empty fr et0.

2014-03-05

EXP510, DS4800, SAN, Switch, Power720接線圖和開、關機順序


1. 開機順序

          SAN Switch or Switch -> EXP510 -> DS4800(註1) -> HMC -> Power720

          註1:查詢DS4800的IP Address

1. 接妥console線, 查詢通用序列匯流排號碼
2. 開啟putty連結時透過 Ctrl + Break 按鍵進行正確字元的切換, 當出現正確的字元時, 再按 Esc 按鍵
3. login/password: shellUsr / w3oo&w4
4. 輸入 netCfgSet




1. 關機順序

   LPAR -> Power720 -> HMC -> DS4800 -> EXP510 -> SAN Switch or Switch


接線圖

vCenter Site Recovery Manager

  • 以一個site為單位, 每一個site一定要有一個vCenter和一個SRM
  • VR
    • 是透過網路的方式進行檔案複寫(file-level), 但其實傳輸的時候也是用block-level的方式進行傳送, RPO(採用非同步)=15min~24hr
    • 非同步的方式進行傳輸
    • 關於state的部分, 若guest os是windows os(Windows 2003版本以上), vmware tools會呼叫VSS的機制儲存, linux則無
    • plan migration會先將guest os先shutdown, 確保state可以寫回硬碟.
    • 只會拷貝開機狀態的Guest OS的檔案.
    • 若Protected端有做snapshot時, 複製到recovery端的時候會被合併
    • 被管理的IP要指向vCenter Server
    • 第一次會用完全的複寫方式到Recovery端, 複寫的過程不會做壓縮也不會做加密, 之後的複寫都是用ESXi內建的CBT(Change Block Tracking)的方式做複寫.
  • Array-based
    • 會透過LUN(block-level)的方式進行複寫
    • 同步/非同步的方式傳輸(遠端的方式可能無法用同步的方式)
    • SRA的版本最好是要一樣, 且Storage也最好是相同的廠牌
  • SRM5.1(只負責控制)到另一個site是可以透過Recovery plan(這個是可以自行定義的)自行定義啟動的優先順序
    • 不需要設定為Linked mode
    • SRM API是採用SOAP的方式, 也就是用XML語法的方式作為與其他平台做資料交換
    • 可以安裝在虛擬機器上
    • 需安裝在Windows 64bit的作業系統上
    • 若是走Storage Array的方式, 儲存設備廠商必須提供SRA(storage replication adapters)
    • support DB2、SQL Server、Oracle
    • 沒有support Storage vMotion和Storage DRS
  • SRM5.5新功能
    • 支援Storage vMotion
    • 可保留VM的前24個複寫狀態
    • 支援Flash cache(SSD)
  • Vmotion Latency need <= 5ms 的網路品質, 來源端和目的端的Port group需一樣
  • Metro Vmotion Latency need <= 10ms 的網路品質
  • placeholder:virtual machine的快照和設定
  • VMkernel無法對應, 只能對應Port group
  • Network Port group若更改名稱的話, 必須重新建立
  • Protection Group:一群需要從Protection site端切換到Recovery site端的Guest OS
    • 建立完成之後會放在未來的Recovery Plan(自動化災難移轉)去做應用
  • Recovery plan
    • 是建立在Recovery Site的
    • 還原時可以被定義是連接哪一個網路, 以避免與正式環境起衝突; 可透過一個dr-ip-customizer.exe小工具進行大量修改IP
    • 可以修改開機順序, Power on之後馬上就會接下一個群組, 無法設定開機後delay多久才開啟第二個群組, 只能設定dependencies
    • 每個Guest OS要確保都已安裝VMware Tools
    • 只要Guest OS是Microsoft OS(windows2000, 2003, xp)的環境, 建議安裝User Profile Hive Cleanup Services以加速關機作業

2014-01-24

DB2 user space 調整

Administrator
ITM@Admin


至DB2 GUI控制中心 -> 右鍵要增加容量的DB
管理儲存體 -> 新增自動儲存體 -> 增加位置 
db2 connect to database_name
db2 alter database add storage on 'd:\'
db2 connect reset
db2 connect to database_name 
db2 ALTER TABLESPACE tablespace_name REBALANCE

2014-01-12

ITM CEC Base agent issue

ITM CEC Base agent重啟後,ITM無法顯示CEC的數據,解決步驟如下:

STEPS TO RECYCLE THE SHARED MEMORY:
1.
Stop all the processes which use the SPMI shared library
(xmservd,filtd, xmperf, 3dmon, ptxrlog, harmd, topas, any PSSP process)
if they are currently running your AIX LPAR. 


2.
Stop the ITM system P agents (PX, PK, PH) that you have running on
this system. 


3.
To find if any zombie processes are running on your machine.
a. Run
# ps -ef | grep Provider
Kill each one of them "kill <pid> 


b. Run
ps -ef | grep kpkagent
ps -ef | grep kpxagent
ps -ef | grep kphagent
Kill each one of them "kill <pid>" 


c.
Check if there are any defunct processes
"ps -ef | grep defunct" 


4. Kill the processes that are using the shared memory. 
genld -l | grep -p Spmi 

5.
Run "ipcs -m" command and check for any segment "KEY" that begins
with '0x78'
, as listed below:
T ID KEY
m 0 0xc76283cc
m 1 0x78002323
If there are any such segments starting with 0x78, make sure the process
which uses those shared segments is stopped (or terminate it with kill
command) 


6. Then run: "ipcrm -m <ID #>" to
clear the shared memory segments. 

7.
Run "slibclean"

8. Restart system P agents - PH PX PK 


2013-10-03

Allocate memory by Perl

仿效Java先allocate memory的作法可試著用Perl來做實驗, 作法如下:

#!/usr/bin/perl -w

for (0..10){
   my $buf = "A" x (1024 * 1024 * 100);
   print "Allocated " . length($buf) . " byte buffer\n";

}
print "Finished\n";
sleep(1000);

2013-09-16

透過HMC指令列出LPAR的資訊

hscroot@localhost:~> lssyscfg -r sys -F name
Server-9179-MHC-SN06394FR

hscroot@localhost:~> lssyscfg -m Server-9179-MHC-SN06394FR -r lpar -F name,lpar_id,state,rmc_ipaddr
TS1-1,16,Running,10.199.130.158
FGW2-1,15,Running,10.199.130.157
FGW1-1,14,Running,10.199.130.156
DEV1,13,Running,10.199.130.155
WORKING_LPAR,12,Running,10.199.130.154
NIM_Server,11,Running,10.199.130.153
DAP2-1,10,Running,10.199.130.51
DAP1-1,9,Running,10.199.130.1
DAR2-1,8,Running,10.199.130.136
DAR1-1,7,Running,10.199.130.131
LOG2,6,Running,10.199.130.122
LOG1,5,Running,10.199.130.121
MDS2,4,Running,10.199.130.112
MDS1,3,Running,10.199.130.111
VIOS2,2,Running,10.199.130.152

VIOS1,1,Running,10.199.130.151


Reference
1. http://www.aixhealthcheck.com/blog.php?id=227
2. http://santosh-aix.blogspot.tw/2008/06/creating-lpar-from-hmc-command-line.html

2013-08-06

ITM Agent change hostname

在TEP上,遇到Agent端的hostname有重複的時候,TEP管理的介面上會一直出現更新的訊息(圖1)。因此需要在Agent端做一些調整,方能解決問題。
(圖1)

On Linux/UNIX agent systems, these parameters can be added to the xx.ini file, where xx is the product code of the agent.

Example: edit the xx.ini file and add the following lines, where <your hostname> = the name you chose
to have displayed in the TEP navigator tree.
CTIRA_HOSTNAME=<your hostname>
CTIRA_SYSTEM_NAME=<your hostname>

After making the changes to the file and saving it, a restart of the agent is required.


For the Windows agents, you need to perform the following steps:

1) Stop the agent
2) In the TEP Managed System Status workspace, clear the offline entry for the agent
3) Ensure the corresponding navigator item has been removed
4) In the Manage Tivoli Enterprise Monitoring Services (MTEMS) GUI, right-click on the agent and select Advanced->Edit Variables...
5) Click on Add
6) For CTIRA_HOSTNAME, choose the variable from the list of selected variables
7) For the value, replace "%computername%" with the desired hostname, making sure to leave the remaining part of the value (typically .TYPE=REG_EXPAND_SZ) unchanged
8) For CTIRA_SYSTEM_NAME, type in the variable name and also the desired value
9) Select OK and start the Windows OS agent.

Alternative method: The following may be used to manually change the hostname on the Windows system:

1) Stop the agent
2) Clear the offline entry from Managed System Status workspace
3) Ensure the corresponding navigator item has been removed
4) Edit the <ITMHOME>\TMAITM6\kxxcma.ini file to include:
[Override Local Settings]
CTIRA_HOSTNAME=<hostname> .TYPE=REG_EXPAND_SZ
CTIRA_SYSTEM_NAME=<hostname>
where xx is the product code and <hostname> is the desired name to appear in the TEP
5) Reconfigure the agent through the MTEMS
6) Start the agent

Note that all agents running on a system must use the same values for both the CTIRA_HOSTNAME and CTIRA_SYSTEM_NAME parameters. If this construct is not followed, unpredictable results can occur. This applies to agents on all operating systems.

2013-08-01

AIX上壓縮檔處理方式

在AIX上最常見的壓縮檔就是.tar檔了順手整理了一些常見的壓縮檔格式:

.tar.Z file format
   壓縮
      # compress filename.tar
   解壓
      # zcat filename.tar.Z | tar -xvf -

.tar.gz file format
   壓縮
      # tar cvf - folder | gzip > filename.tar.gz
   解壓
      # gunzip -c filename.tar.gz | tar -xvf -

.gz file format (註1)
   解壓
      # gzip -d filename.gz
   壓縮
      # gzip -v filename

.tgz file format
   解壓
      # gzip -d filename.tgz | tar -xvf -

.zip file format (註2)
   解壓
      # unzip filename.zip


註1 : gzip 在壓縮完後,會建立一個 .gz 的檔,並清除原始未壓縮的檔。反之,解壓縮的時候,則是把 .gz 檔清除,只留解開後的檔。

註2 : 請注意,AIX預設並沒有裝unzip的程式。

2013-07-31

AIX增加Paging Space失敗時的檢查及處理流程

root@NIM_SERVER:/#lsps -a
Page Space      Physical Volume   Volume Group    Size %Used Active  Auto  Type Chksum
hd6             hdisk0


root@NIM_SERVER:/#lslv hd6
LOGICAL VOLUME:     hd6                    VOLUME GROUP:   rootvg
LV IDENTIFIER:      00f7394f00004c000000013ae4b1d3cb.2 PERMISSION:     read/write
VG STATE:           active/complete        LV STATE:       opened/syncd
TYPE:               paging                 WRITE VERIFY:   off
MAX LPs:            512                    PP SIZE:        128 megabyte(s)
COPIES:             2                      SCHED POLICY:   parallel
LPs:                44                     PPs:            90
STALE PPs:          0                      BB POLICY:      non-relocatable
INTER-POLICY:       minimum                RELOCATABLE:    yes
INTRA-POLICY:       middle                 UPPER BOUND:    32
MOUNT POINT:        N/A                    LABEL:          None
MIRROR WRITE CONSISTENCY: off                                  
EACH LP COPY ON A SEPARATE PV ?: yes                                  
Serialize IO ?:     NO                                  
INFINITE RETRY:     no

root@NIM_SERVER:/#chps -s 1 hd6
0516-404 allocp: This system cannot fulfill the allocation request.
        There are not enough free partitions or not enough physical volumes 
        to keep strictness and satisfy allocation requests.  The command
        should be retried with different allocation characteristics.


root@NIM_SERVER:/#lspv
hdisk0          00f7394fe4b1d24f                    rootvg          active    
hdisk1          00f7394fe4b1d2e0                    rootvg          active


root@NIM_SERVER:/#lspv hdisk0
PHYSICAL VOLUME:    hdisk0                   VOLUME GROUP:     rootvg
PV IDENTIFIER:      00f7394fe4b1d24f VG IDENTIFIER     00f7394f00004c000000013ae4b1d3cb
PV STATE:           active                                  
STALE PARTITIONS:   0                        ALLOCATABLE:      yes
PP SIZE:            128 megabyte(s)          LOGICAL VOLUMES:  17
TOTAL PPs:          799 (102272 megabytes)   VG DESCRIPTORS:   2
FREE PPs:           0 (0 megabytes)          HOT SPARE:        no
USED PPs:           799 (102272 megabytes)   MAX REQUEST:      256 kilobytes
FREE DISTRIBUTION:  00..00..00..00..00                      
USED DISTRIBUTION:  160..160..159..160..160                  
MIRROR POOL:        None                                    
root@NIM_SERVER:/#r 0=1
lspv hdisk1
PHYSICAL VOLUME:    hdisk1                   VOLUME GROUP:     rootvg
PV IDENTIFIER:      00f7394fe4b1d2e0 VG IDENTIFIER     00f7394f00004c000000013ae4b1d3cb
PV STATE:           active                                  
STALE PARTITIONS:   0                        ALLOCATABLE:      yes
PP SIZE:            128 megabyte(s)          LOGICAL VOLUMES:  17
TOTAL PPs:          799 (102272 megabytes)   VG DESCRIPTORS:   1
FREE PPs:           228 (29184 megabytes)    HOT SPARE:        no
USED PPs:           571 (73088 megabytes)    MAX REQUEST:      256 kilobytes
FREE DISTRIBUTION:  00..00..00..68..160                      
USED DISTRIBUTION:  160..160..159..92..00                    
MIRROR POOL:        None


root@NIM_SERVER:/#smitty jfs2
調整hd6的空間, 將其空間縮小。


root@NIM_SERVER:/#lspv hdisk0
PHYSICAL VOLUME:    hdisk0                   VOLUME GROUP:     rootvg
PV IDENTIFIER:      00f7394fe4b1d24f VG IDENTIFIER     00f7394f00004c000000013ae4b1d3cb
PV STATE:           active                                  
STALE PARTITIONS:   0                        ALLOCATABLE:      yes
PP SIZE:            128 megabyte(s)          LOGICAL VOLUMES:  17
TOTAL PPs:          799 (102272 megabytes)   VG DESCRIPTORS:   2
FREE PPs:           34 (4352 megabytes)      HOT SPARE:        no
USED PPs:           765 (97920 megabytes)    MAX REQUEST:      256 kilobytes
FREE DISTRIBUTION:  00..00..00..00..34                      
USED DISTRIBUTION:  160..160..159..160..126                  
MIRROR POOL:        None


root@NIM_SERVER:/#chps -s 1 hd6


root@NIM_SERVER:/#lsps -a
Page Space      Physical Volume   Volume Group    Size %Used Active  Auto  Type Chksum
hd6             hdisk0            rootvg        5760MB     1   yes   yes    lv     0


root@NIM_SERVER:/#lslv hd6
LOGICAL VOLUME:     hd6                    VOLUME GROUP:   rootvg
LV IDENTIFIER:      00f7394f00004c000000013ae4b1d3cb.2 PERMISSION:     read/write
VG STATE:           active/complete        LV STATE:       opened/syncd
TYPE:               paging                 WRITE VERIFY:   off
MAX LPs:            512                    PP SIZE:        128 megabyte(s)
COPIES:             2                      SCHED POLICY:   parallel
LPs:                45                     PPs:            90
STALE PPs:          0                      BB POLICY:      non-relocatable
INTER-POLICY:       minimum                RELOCATABLE:    yes
INTRA-POLICY:       middle                 UPPER BOUND:    32
MOUNT POINT:        N/A                    LABEL:          None
MIRROR WRITE CONSISTENCY: off                                  
EACH LP COPY ON A SEPARATE PV ?: yes                                  
Serialize IO ?:     NO                                  
INFINITE RETRY:     no

2013-06-18

IBM DB2 管理

●必要的授權角色

在 UNIX 上,執行此程序的使用者必須具有 root 專用權。而在 Windows 上,執行此程序的使用者必須具有 Administrators 群組的成員資格。還必須要有有效的使用者名稱和密碼,才能存取管理伺服器的必要資料庫。


●開始之前

管理伺服器的資料庫必須使用 UTF8 編碼,才能處理非 ASCII 值 (例如中文字元)。

●程序
這些程序會提供範例指令。實際指令和值也許會因您的環境而不同。

  1. 執行下列作業,讓 DB2 7.2 版能夠使用 IBM Tivoli Monitoring for Transaction Performance 所需的已更新 Java 功能:
    1. 停止 DB2 服務。
    2. 存取您的 DB2 安裝的 SQLLIB\java12 目錄。
    3. 執行程式,以更新 IBM DB2 7.2 版的 Java 功能:
      • 在 Windows 型環境中,執行 usejdbc2.bat 批次檔。
      • 在 UNIX 型環境中,執行 usejdbc2 Script。
    4. 重新啟動 DB2。
  2. 執行下列作業以建立資料庫:
    1. 在供管理伺服器使用的電腦上安裝 DB2 用戶端。
    2. 使用下列指令以建立資料庫:
      db2 "create database database_name"
      其中 database_name 是資料庫的名稱。
      範例:如果 db2Admin 是在管理伺服器上安裝 DB2 資料庫用戶端的 使用者名稱,您可以使用 db2Admin 來登入,並建立名為 itmtpDB 的資料庫 以支援管理儲存庫。
      db2 "create database itmtpDB"
      相關資訊:在與該用戶端關聯的「DB2 實例」下建立供管理伺服器使用的資料庫。 為了建立資料庫,您可以 DB2 實例的授權使用者來登入, 或以 DB2 用戶端以其身份而安裝的。安裝 DB2 用戶端的使用者能夠存取與用戶端有關聯的所有 DB2 實例。
    3. (僅限雙位元組字元環境):例如, 語言環境設為中文、韓文或日文的作業系統,需要雙位元組字集。如果您的作業系統啟用單位元組字集, 則不會自動接受雙位元組字集。您必須明確地啟用資料庫,以儲存含有雙位元組字元字串的監視資訊。下列建立資料庫的指令,會啟用雙位元組字集的儲存體:
      - DB2: CREATE DATABASE database_name USING CODESET UTF-8 TERRITORY US
  3. 執行下列作業,在 DB2 伺服器機器的作業系統上建立資料庫使用者。
    1. 直接在伺服器上,或從 DB2 用戶端中,建立資料庫使用者。
      相關資訊:資料庫使用者一詞指的是管理伺服器用於存取支援管理儲存庫之 DB2 資料庫的系統使用者帳號。範例:如果 DB2 伺服器是安裝在 Windows 電腦上, 則您可以在該機器的 DOS 提示中輸入下列指令,建立管理伺服器可用於存取管理儲存庫的資料庫使用者帳戶。 此指令範例會建立一個名為 itmtp52 的使用者,其密碼為 TIMS。 (此密碼是第二個 itmtp52項目。)
      net user itmtp52 itmtp52 /add
  4. 執行下列作業,建立並實作緩衝池:
    註:
    DB2 的預設緩衝池和頁面大小,比使用管理儲存庫的應用程式所需的最佳效能還要小。 請使用大小至少為 250 的緩衝池。
    若要實作緩衝池,您必須中斷目前連接資料庫之所有應用程式的連線。
    1. 建立大型緩衝池,不使用作業系統分頁,將大小儘可能設為最大。
      相關資訊:例如,若要建立大小為 250、頁面大小為 32K 的緩衝池, 請在 DB2 中輸入下列指令:
      create bufferpool buffpool32k size 250 pagesize 32k
    2. 使用 APPLHEAPSZ 512 指令,更新 <database_name> 的資料庫配置。
    3. 輸入下列指令來檢視新緩衝池:
      select * from syscat.bufferpools
    4. 使用下列指令,列出目前連接至資料庫的所有應用程式:
      db2 list applications
      畫面會顯示類似以下的應用程式清單:
      Auth ID   Appl.  Appl.      Application ID            DB     #of
                Name   Handle                               Name  Agents
      --------  ----   ------  ---------------------------  ----  ------
      DB2INST1  java     14   *LOCAL.db2instl.000918161203  CSWA    1
      DB2INST1  java     15   *LOCAL.db2instl.000918161204  CSWA    1
    5. 關閉連接至資料庫的所有 連線,針對目前連接的每一個應用程 式,重複執行下列指令:
      db2 force application (applicationhandle)
      其中 applicationhandle 是列在應用程式清單之 Appl. Handle 直欄中的應用程式處理號碼 (請參閱步驟 4d)。
    6. 以下列其中一種方式重新連接至資料庫:
      • 如果您是以 DB2 實例的授權使用者 (資料庫以其身份而建立) 登入,請輸入類似下列的指令:
        db2 "connect to databasename"
        其中 databasename 是要供管理伺服器使用之資料庫的名稱。
        --或--
      • 如果您不是以 DB2 實例的授權使用者 (資料庫以其身份而建立) 登入,請輸入類似下列的指令:
        db2 "connect to databasename user InstUser using InstUserPasswd"
        其中:
        • databasename 是要供管理伺服器使用之資料庫的名稱。
        • InstUser 和 InstUserPasswd 是 DB2 實例之授權使用者(資料庫以其身份而建立) 的使用者 ID 和密碼。
        顯示的資訊與下面的類似:
        $db2 connect to cswa
        
        Database Connection Information
        Database server      = DB2/6000 7.1.0
        SQL authorization ID = DB2INST1
        Local database alias = CSWA
  5. 執行下列作業,建立表格空間:
    註:
    下列範例程序會建立一個新的表格空間,並將其與大小為 250、頁面大小為 32K 的緩衝池產生關聯。 您必須先建立好使用者表格空間,然後才能建立系統暫存表格空間。
    注意下列表格空間預估一個月的作業資料。不過,空間需求會視您的環境及您對產品的配置方式而有差異。
    1. 使用下列指令,捨棄預設的使用者表格空間 (userspace1):
      drop tablespace userspace1
    2. 輸入類似下列範例的指令,重建預設使用者表格空間:
      create tablespace userspace1 pagesize 32 k managed by system
      using ('/data2/tablespace1' 250)
      bufferpool bp32k
    3. 若要建立系統暫存表格空間,請輸入類似下列範例的指令:
      create temporary tablespace tempspace pagesize 32 k managed by system
      using ('/data2/temp32k')
      bufferpool bp32k
    4. 若要檢視變更,輸入下列指令:
      db2 list tablespaces show detail
  6. 使用下列指令,將許可權授與資料庫使用者 (管理伺服器用於存取資料庫的使用者帳戶):
    註:
    資料庫使用者必須有建立和編輯表格的權限。
    db2 "grant dbadm on database to user user"
    db2 "grant use of tablespace tablespace to user user"
    其中:
    • user 是資料庫使用者的使用者 ID
    • tablespace 是要為管理伺服器建立的表格空間名稱。
    相關資訊:這些指令會授與資料庫及表格空間的 DBADM 權限。 若要發出這些指令,您必須以獲得「DB2 實例」授權,並且用來建立資料庫的使用者登入。
    範例:若要建立資料庫使用者 itmtp52 以供管理伺服器使用 (如步驟 3 下的範例),並建立表格空間 userspace1 (如步驟 5 下的範例), 請使用下列指令,授與使用資料庫及表格空間的權限。
    db2 "grant dbadm on database to user itmtp52"
    db2 "grant use of tablespace userspace1 to user itmtp52"
  7. 選用) 您可以使用下列程序, 驗證 DB2 資料庫配置是否已最佳化。
    註:
    此範例程序會增加日誌優先項目的數目,然後開啟日誌保存功能,將配合 IBM Tivoli Monitoring for Transaction Performance 應用程式使用的資料庫配置最佳化。
    1. 輸入類似下列指令,以列出資料庫配置資訊:
      db2 "get db cfg for databasename"
    2. 輸入類似下列範例的指令,增加主要日誌的數量:
      db2 "update db cfg for databasename using logprimary number"
    3. 輸入類似下列指令,以開啟日誌保留功能:
      db2 "update db cfg for databasename using logretain on"
    4. 列出目前連接至資料庫的所有應用程式。請使用下列指令:
      db2 list applications
      畫面會顯示類似以下的應用程式清單:
      Auth ID   Appl.  Appl.      Application ID            DB     #of
                Name   Handle                               Name  Agents
      --------  ----   ------  ---------------------------  ----  ------
      DB2INST1  java     14   *LOCAL.db2instl.000918161203  CSWA    1
      DB2INST1  java     15   *LOCAL.db2instl.000918161204  CSWA    1
    5. 關閉所有到資料庫的連線。為目前已連接的每一個應用程式重複下列指令:
      db2 force application (applicationhandle)
      其中 applicationhandle 是列在應用程式清單之 Appl. Handle 直欄中的應用程式處理號碼 (請參閱步驟 7d)。
    6. 製作離線備份並套用 db 日誌到捲動轉遞。輸入與下列相類似的指令:
      db2 "backup db databasename to backupdirectory"
    7. 重複步驟 7d。
  8. 執行下列作業,設定 DB2 用戶端連線:
    註:
    若 DB2 RDBMS 是安裝在與用戶端 (管理伺服器) 不同的機器上,您必須在用戶端機器上安 裝 DB2 Client Application Enabler,並設定至資料庫的連線。
    相關資訊:安裝及配置 DB2 Client Application Enabler 時,請遵循這些指引:
    • 請確定在系統上沒有安裝「DB2 用戶端應用程式啟用程式」(不論是完整或部份安裝)。若安裝已存在,請將它解除安裝。
    • 自訂選項以選取 Java Database Connectivity (JDBC)。JDBC 驅動程式被安裝成部份的「DB2 用戶端應用程式啟動程式」安裝環境。
    • 確定在選取的起始目錄中,有大約 2 MB 的可用空間以容納「DB2 用戶端應用程式啟用程式」。
    • (僅限 UNIX 型系統) 執行 db2profile 檔案 (適用於 Korn 或 Bourne Shell) 或 db2cshrc 檔案 (適用於 C Shell),以便能夠執行 DB2 指令及公用程式,例如 catalog 及 connect。
      db2profile 和 db2cshrc 檔案位於 DB2 實例擁有者的起始目錄,該目錄在 sqllib 子目錄下面。 從每個需要使用 DB2 環境和工具的帳戶的 .profile 或 .cshrc 檔案取得適當檔案。
    • (僅限 AIX) 若要驗證 RDBMS 和 DB2 用戶端的設定,請確認下列環境變數已正確設定。(若您已取得 db2profile 或 db2cshrc 檔案,那麼這些變數是正確的。)
      • DB2DIR 必須指向到「DB2 用戶端應用程式啟動程式」安裝的目錄。
      • DB2INSTANCE 必須設為資料庫實例名稱。這會在資料庫安裝時設定。
    「DB2 用戶端應用程式啟動程式」安裝之後,必須設定到 RDBMS 伺服器和到資料庫的連通性。設定連通性的 DB2 指令是從用戶端系統所發出。即使 DB2 是在掌管管理伺服器的電腦上執行,您也必須執行這些指令。
    • 下列範例指令會將用戶端連接到稱為 ghost 的 RDBMS 伺服器,其具有節點名稱或別名 ims_db2 並使用埠 50000:
      db2 "catalog tcpip node ims_db2 remote ghost server 50000"
    • 下列範例指令會將用戶端連接到稱為 timsdev 的資料庫 (別名為 ims_dev), 此資料庫位於節點名稱或別名為 ims_db2 的伺服器上:
      db2 "catalog database timsdev as ims_dev at node ims_db2"
  9. 執行下列作業,提供額外共用記憶體區段供 AIX 上的 DB2 連線使用:
    註:
    根據預設值,AIX 並不允許 32 位元應用程式,在執行每個處理程序時,連接至超過 11 個的共用記憶體區段,而這其中本端 DB2 連線最多只能使用 10 個。請使用 EXTSHM (延伸共用記憶體) 功能,確保有足夠數量的共用記憶體區段可供 DB2 連線使用。EXTSHM 功能在 DB 7.2 版 (安裝 DB2 UDB 7.1 版 Fix Pack 3 的結果) 或更新版本的 DB2 裡都能使用。若您未提供足夠的共用記憶體區段數量,可能會看到下列錯誤訊息:
    SQL1224N  無法啟動一個資料庫代理站來為這個要求服務,
    或由於資料庫系統關閉或強制命令而導致資料庫代理站
    終止。SQLSTATE=55032
  10. 啟用 EXTSHM,指令如下:
    • 在 DB2 用戶端階段作業中:export EXTSHM=ON
    • 啟動 DB2 UDB 伺服器時:
      export EXTSHM=ON
      db2set DB2ENVLIST=EXTSHM
      db2start
    • 在 DB2 UDB EEE 上:
      EXTSHM=ON
      export EXTSHM
      您也要將這幾行新增到 sqllib/db2profile。

2013-04-26

Export and Import ITM Situation

很感謝ITM官方文件有提到Situation該如何匯出和匯入,如下:
  • 匯出的方法
tacmd viewSit {-s|--situation} SITNAME
                              [{-e|--export} [FILENAME]]
  • 匯入的方法
tacmd createSit {-i|--import} filename
若我們欲匯出的項目僅一至兩個時,透過上述的方法真的很方便,但是當項目變多時,可能還是得透過一些Script來幫忙我們了。透過原廠文件上提到的tacmd listSit指令先將Situation匯出至文字檔,再來我們就可以運用簡易的Script去完成大量Situation的匯出和匯入了。


  • Situation的匯出


  • Situation的匯入



2013-03-27

記錄process list...PART1

蒐集系統上的process,目的是為了日後評估哪些process是系統和應用程式運行所必要的,今日先透過script來收集和統計process的清單。




##########################################################
## Target:                                            
## collect & filter uid, pid, ppid and cmd column
## from ps -ef result then export to record      
##                                                    
## Date:   2013/03/27                              
## Ver:    1.0                                        
## Author: Jammy Yu                                  
##########################################################

my $chk_time = `date +%Y%m%d`;
my @process = `ps -ef | grep -v UID`;

chomp($chk_time);

open(FHD, ">> /TWSE/process/process_$chk_time.log") || die "$!\n";

foreach (@process)
{
   chomp;
 
   ##     $1=UID  $2=PID $3=PPID                   $4=CMD
   $_ =~ /(\w+)\s+(\d+)\s+(\d+).+?[-|pts].+?:.+?\s+(.+)/;
 
   print FHD "$1,$2,$3,$4\n";
}

close(FHD);



open(LOG, " /TWSE/process/process_$chk_time.log") || die "$!\n";

my @cmd;
my %count;
while ( <LOG> )
{
   chomp;
   my($uid, $pid, $ppid, $cmd) = split(/\,/, $_);
   push(@cmd, $cmd);
}

foreach (@cmd)
{
   if (exists $count{$_})
   {
      $count{$_}++;
   }
   else
   {
      $count{$_} = 1;
   }
}

foreach (keys %count)
{
   print "$_ ---> $count{$_} time(s)\n";
}

close(LOG);

2013-03-26

透過背景模式進行ITM Agent安裝

先前安裝ITM Agent至90台LPAR時,若沒有善加運用背景執行程序的方法,當安裝1台需花費10分鐘的話,90台至少就要花費900分鐘!所以透過ssh中提供的f參數時,則可將程序丟到背景執行以達到同一時間並行運行安裝程序。


#!/usr/bin/ksh

for HOST in `cat /tmp/host.lst`;
do
   echo "$HOST start....."
   ssh -p 2222 -f $HOST '/tmp/agent_silent_install.pl'
 
   ExecStatus=$?
   if [ $ExecStatus -eq 0 ]; then
      echo "$HOST finish..." >> /tmp/itm.log
   else
      echo "$HOST fail..." >> /tmp/itm.log
   fi
done

2013-03-20

在AIX上移除^M字元

在Windows系統上,若將編輯後的文字檔上傳至AIX系統時,我們可能會發現文字檔案中的每一行皆會出現^M字元,經由同事告知解決的方式,當然要不吝嗇得分享給大家,作法有下列二種:
1.cat dosfile | col -b > unixfile

2.tr -d "\015\032" < dosfile > unixfile

2013-03-15

程序並行運行測試



配合測試需在觀察在同個時間點並行執行15個程序,且程序中皆須要有I/O的行為,原本想使用Perl的Thread Function,但其實shell就提供好用的pipe模式,下列三個情境可參考:

一、若程序相關,用管道便可以完成
cmd1 | cmd2 |...| cmdN

二、若完全無關聯,可以用job的方式
cmd1&; cmd2& ...& cmdN&

三、用script也可以,但下列的方式僅限於兩個!
perl -e 'fork() ? `cmd1` : `cmd2`'

而這次是採用第一個情境,並透過dd來產生1GB的檔案,產生檔名的方式是利用亂數來命名,簡易的Script如下所示:


#!/usr/bin/perl

my $rand=rand 3;
`dd if=/dev/zero of="$rand"_file_1GB bs=1m count=1k`;



當執行完成後,檔案名稱很幸運都沒有重複到

2012-10-23

ITM Agent Owner由ROOT轉換為Normal User

啟用ITM Agent的Owner預設會是由root所持有,但使用者不希望當Agent發生異常時,需要透過root才能重新啟動Agent的服務,因此經由IBM工程師給的建議和執行程序,我將它簡單的編譯成Script,主要還是方便透過這支Script來修改多台系統的配置,程序如下:


#!/usr/bin/perl -w
use strict;
##################################################
## Target:                                         ##
## transfer itm agent owner to normal user          ##
## ##
## 1.chown -R seadm:se /opt/IBM/ITM/ ##
## 2.chmod -R o-rwx /opt/IBM/ITM/ ##
## 3./opt/IBM/ITM/bin/SetPerm.sh ##
## 4./opt/IBM/ITM/bin/UpdateAutoRun.sh ##
## 5./opt/IBM/ITM/bin/itmcmd agent stop all ##
## 6.Disable ux agent under /etc/rc.itm1 ##
## 7./etc/rc.itm1 ##
## ##
## Date:   2012/10/22 ##
## Ver:    1.2 ##
## Author: Jammy Yu ##
##################################################

## Initial setup
my $command;
my $source_dir = '/tmp';
my $env_dir = '/etc';
my $itm_dir = '/opt/IBM/ITM';
my $user = 'seadm';
my $group = 'se';
my $time = `date +%Y-%m-%d_%H:%M:%S`;

##################################################
## 0. Initial test ##
##################################################
print"Transfer agent owner from root to $user has Step0~7:\n";
print"-" x 52,"\n";
print"step0...Initial check\t\t\t";
if (!-e "$itm_dir") {
   print "Please check itm has been installed first!\n";
   exit 1;
}
if (!-e "$source_dir/agent_owner_transfer_SetPerm") {
   print "Please check agent_owner_transfer_SetPerm file has been under $source_dir dir!\n";
   exit 1;
}
print"OK!\n";

##################################################
## 1.chown -R seadm:se /opt/IBM/ITM/ ##
##################################################
print"step1...Chown -R $user:$group /opt/IBM/ITM/\t";
$command = "/usr/bin/chown -R $user:$group $itm_dir";
`$command`;
print"OK!\n";

##################################################
## 2.chmod -R o-rwx /opt/IBM/ITM/ ##
##################################################
print"step2...Chmod -R o-rwx /opt/IBM/ITM/\t";
$command = "/usr/bin/chmod -R o-rwx $itm_dir";
`$command`;
print"OK!\n";

##################################################
## 3./opt/IBM/ITM/bin/SetPerm ##
##################################################
print"step3...Running SetPerm.sh\t\t";
if (-e "$itm_dir/bin/SetPerm")
{
   $command = "/usr/bin/cp -f $itm_dir/bin/SetPerm $itm_dir/bin/SetPerm.bak_$time";
   `$command`;
   $command = "/usr/bin/cp -f $source_dir/agent_owner_transfer_SetPerm $itm_dir/bin/";
   `$command`;
   $command = "$itm_dir/bin/agent_owner_transfer_SetPerm";
   `$command`;
}
else
{
   $command = "/usr/bin/cp -f $source_dir/agent_owner_transfer_SetPerm $itm_dir/bin/";
   `$command`;
   $command = "$itm_dir/bin/agent_owner_transfer_SetPerm";
   `$command`;
}
print"OK!\n";

##################################################
## 4./opt/IBM/ITM/bin/UpdateAutoRun.sh ##
##################################################
print"step4...Running UpdateAutoRun.sh\t";
$command = "$itm_dir/bin/UpdateAutoRun.sh";
`$command`;
print"OK!\n";

##################################################
## 5./opt/IBM/ITM/bin/itmcmd agent stop all ##
##################################################
print"step5...Stop itm agent\t\t\t";
$command = "$itm_dir/bin/itmcmd agent stop all >/dev/null 2>&1";
`$command`;
print"OK!\n";

##################################################
## 6.Disable ux agent under /etc/rc.itm1 ##
##################################################
print"step6...Disable ux agent line\t\t";
if (-e "$env_dir/rc.itm1")
{
   $command = "/usr/bin/cp -f $env_dir/rc.itm1 $env_dir/rc.itm1.bak_$time";
   `$command`;
}

open(TMP, "$env_dir/rc.itm1.bak_$time") || die "$!\n";
open(FHD, "> $env_dir/rc.itm1") || die "$!\n";

while ( <TMP> )
{
   chomp;
   if ( /ux/ )
   {
      $_ =~ s/$_/#$_/;
      print FHD "$_\n";
   }
   else
   {
      print FHD "$_\n";
   }
}

close(FHD);
close(TMP);

print"OK!\n";

##################################################
## 7.re-execute /etc/rc.itm1 ##
##################################################
print"step7...Running /etc/rc.itm1\t\t";
$command = "$env_dir/rc.itm1";
`$command`;
print"OK!\n";
print"-" x 52,"\n";

2012-10-13

透過Silent Install的模式進行ITM Agent的安裝和配置

當需要安裝ITM Agent數量變多的時候,我們可能會希望讓系統自行安裝和配置,甚至於順便啟動服務。

下列提供的作法共分為七個步驟,分別是:

1.安裝Unix OS Agent、AIX Premium Agent和Unix LOG Agent
2.將原先kul_config檔案備份並將定義好的kul_config檔案拷貝至/opt/IBM/ITM/config目錄下
3.檢查Unix LOG Agent欲檢查的目錄及檔案是否存在
4.將原先syslog.conf檔案備份並將定義好的syslog.config檔案拷貝至/etc目錄底下
5.重新啟動syslog daemon
6.將ITM Agent安裝檔刪除
7.僅啟動AIX Premium和Unix LOG Agent,故必須把Unix OS Agent自動帶起服務的項目先Disable




#!/usr/bin/perl -w
use strict;
##################################################
## Target                                                                                 ##
## 1.Install & Config ul,ux,px agent                                        ##
## 2.Replace ITM config file:kul_configfile                              ##
## 3.Check directory and files for ul agent                          ##
## 4.Replace syslog entry to /etc/syslog.conf                            ##
## 5.Start syslogd but ITM agent                                          ##
## 6.Delete temp ul ux px agent directory                               ##
## 7.Disable ux agent from /etc/rc.itm1 file                              ##
## ##
## Date:   2012/10/12         ##
## Ver:    1.7         ##
## Author: Jammy Yu ##
##################################################

## Initial setup
my $source_dir = '/TWSE';
my $install_dir = '/opt/IBM/ITM';
my $env_dir = '/etc';

## Package source
my %agent_relation = (
"ux" => "$source_dir/ITM_V6.2.3_Agent_Multiplatform",
"ul" => "$source_dir/ITM_V6.2.3_Agent_Multiplatform",
"px" => "$source_dir/ITM_Agents_SystemP_V6.2.2",
);

## LOG record
open(LOG, ">$source_dir/agent_install.log") || die "$!\n";

## Start Program
my $start_time = `date +%Y-%m-%d_%H:%M:%S`;

print LOG "Program start time:$start_time\n";

##################################################
## 1.Install & Config ul,ux,px agent                                 ##
##################################################
while (my ($agent_name, $agent_source_dir) = each (%agent_relation))
{
   ## Check source agent directory
   if (!-e "$agent_source_dir")
   {
      print"ERROR: Please check source agent directories are aready under the $source_dir directory\n";
      exit 1;
   }
   ## Chmod agent Directory
   `chmod -R 777 $agent_source_dir`;
   print LOG "Chmod agent Directory:$agent_source_dir to 777\n";
   ## Install agent
   `$agent_source_dir/install.sh -q -h $install_dir -p $agent_source_dir/$agent_name\_silent_install.txt`;
   print LOG "Install agent name:$agent_name,\t Source agent dir:$agent_source_dir\n";

   ## Config agent
   `$install_dir/bin/itmcmd config -A -p $agent_source_dir/silent_config.txt $agent_name`;
   print LOG "Config agent name:$agent_name\n";
}
print LOG "-" x 80,"\n";

##################################################
## 2.Replace /opt/IBM/ITM/config/kul_configfile                 ##
##################################################
my $itmconfig_dir = '/opt/IBM/ITM/config';
my $command;
if (-e "$itmconfig_dir/kul_configfile")
{
   $command = "/usr/bin/mv $itmconfig_dir/kul_configfile $itmconfig_dir/kul_configfile.bak_$start_time";
   `$command`;
   $command = "/usr/bin/cp -f $source_dir/kul_configfile $itmconfig_dir/kul_configfile";
   `$command`;
   $command = "/usr/bin/chmod 777 $itmconfig_dir/kul_configfile";
   `$command`;
}
else
{
   $command = "/usr/bin/cp -f $source_dir/kul_configfile $itmconfig_dir/kul_configfile";
   `$command`;
   $command = "/usr/bin/chmod 777 $itmconfig_dir/kul_configfile";
   `$command`;
}

##################################################
## 3.check directory and files for ul agent                                 ##
##################################################
my %file_relation = (
        "/var/log/syslog/critical_files" => "D",
        "/var/log/syslog/auth_files" => "D",
        "/var/log/syslog/user_files" => "D",
        "/var/log/syslog/sftp_files" => "D",
        "/var/log/syslog/critical" => "F",
        "/var/log/syslog/auth" => "F",
        "/var/log/syslog/user" => "F",
        "/var/log/syslog/sftp" => "F",
);

while (my ($path, $type) = each (%file_relation))
{
=cut
   ## Build directory and files
   if ( $type eq 'D' )
   {
      build_dir($path);
   }
   elsif ( $type eq 'F' )
   {
      build_file($path);
   }
=cut
   ## Check directory and files
   if (-e "$path" )
   {
      print LOG "Type:$type,PATH:$path\t check: Exist!\n";
   }
   else
   {
      print LOG "Type:$type,PATH:$path\t check: Doesn't Exist!\n";
   }
}
print LOG "-" x 80,"\n";

##################################################
## 4.Replace syslog entry to /etc/syslog.conf                         ##
##################################################
if (-e "$env_dir/syslog.conf")
{
   $command = "/usr/bin/cp -f $env_dir/syslog.conf $env_dir/syslog.conf.bak_$start_time";
   `$command`;
   $command = "/usr/bin/cat $source_dir/syslog_build.config > $env_dir/syslog.conf";
   `$command`;
}
else
{
   $command = "/usr/bin/touch $env_dir/syslog.conf";
   `$command`;
   $command = "/usr/bin/cat $source_dir/syslog_build.config > $env_dir/syslog.conf";
   `$command`;
}


##################################################
## 5.Start syslogd but ITM agent                                 ##
##################################################
=cut
`$install_dir/bin/itmcmd agent start px`;
`$install_dir/bin/itmcmd agent start ul`;
=cut

`/usr/bin/stopsrc -s syslogd`;
`/usr/bin/startsrc -s syslogd`;


## Agent status
my $agent_status = `$install_dir/bin/cinfo -r`;
print LOG "ITM install agent status:$agent_status\n";
print LOG "-" x 80,"\n";
my $agent_status = `$install_dir/bin/cinfo -i`;
print LOG "ITM install package:$agent_status\n";
print LOG "-" x 80,"\n";
my $agent_status = `ps -ef | grep syslogd | grep -v grep`;
print LOG "Syslog daemon status:$agent_status\n";
print LOG "-" x 80,"\n";

##################################################
## 6.Delete temp ul ux px agent directory                           ##
##################################################
my $host = `hostname`;
chomp($host);

if ($host ne "WKLPAR")
{
   opendir(DIR, "$source_dir") || die "Can't open dir\n";
   while( defined(my $filename = readdir(DIR)) )
   {
      next if ($filename eq '.' || $filename eq '..');
 
      if (-d "$source_dir/$filename")
      {
         `rm -rf "$source_dir/$filename"`;
         print LOG "Delete directory:$source_dir/$filename\n";
      }
   }
   close(DIR);
}

## End Program
my $end_time = `date +%Y-%m-%d_%H:%M:%S`;
print LOG "Program end time:$end_time\n";

close(LOG);

##################################################
## 7.Disable ux agent from /etc/rc.itm1 file                         ##
##################################################
if (-e "$env_dir/rc.itm1")
{
   $command = "/usr/bin/cp -f $env_dir/rc.itm1 $env_dir/rc.itm1.bak_$start_time";
   `$command`;
}

open(TMP, "$env_dir/rc.itm1.bak_$start_time") || die "$!\n";

open(FHD, "> $env_dir/rc.itm1") || die "$!\n";

while ( <TMP> )
{
   chomp;
   if ( /ux/ )
   {
      $_ =~ s/$_/#$_/;
      print FHD "$_\n";
   }
   else
   {
      print FHD "$_\n";
   }
}

close(FHD);

close(TMP);

##################################################
## Subroutine                                            ##
##################################################
sub build_dir
{
   my $directory = shift;
   my $command;

   if (-e $directory)
   {
      $command = "/usr/bin/mv $directory $directory.bak_$start_time";
      `$command`;
      $command = "/usr/bin/mkdir -p $directory";
      `$command`;
   }
   else
   {
      $command = "/usr/bin/mkdir -p $directory";
      `$command`;
   }

   return;
}

sub build_file
{
   my $file = shift;
   my $command;
   if (-e $file)
   {
      $command = "/usr/bin/mv $file $file.bak_$start_time";
      `$command`;
      $command = "/usr/bin/touch $file";
      `$command`;
   }
   else
   {
      $command = "/usr/bin/touch $file";
      `$command`;
   }

   return;
}