顯示具有 AIX 標籤的文章。 顯示所有文章
顯示具有 AIX 標籤的文章。 顯示所有文章

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.

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-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;
}

2012-10-02

大量修改Crontab Job

當修改多台機器或多個使用者的crontab時,若時間充裕的狀態下,我們可能一台一台主機登入並一一對每個使用者的crontab去做修改,但同時要改9x台主機或多個使用者的話,應該不會想用徒手煉鋼的方式去完成此任務,因此透過每個使用者已預先埋好的ssh key,我們可透過下列這支Script順利完成:

P.S.前提是至少要有三個配置檔,crontab_ssh_host、crontab_ssh_user和crontab_user1,配置檔內容如底端範例所示。



#!/usr/bin/perl -w
use strict;
##################################################
## Target: Deploy cron Job to each host and user##
## ##
## Date:   2012/10/01 ##
## Ver:    1.0 ##
## Author: Jammy Yu ##
##################################################

## Initial setup
my $program_dir = '/tmp/deploy_cronjob';
my $cron_dir = '/var/spool/cron/crontabs';
my @host;
my @user;
my @user_crontab;

## Load host name
open(HOST, "$program_dir/crontab_ssh_host.txt") || die "ERROR:Can't open host file\n";
while ( <HOST> )
{
   chomp;
   next if /^\s+/;
   next if /^#/;
   push(@host, $_);
}
close(HOST);

## Load user name
open(USER, "$program_dir/crontab_ssh_user.txt") || die "ERROR:Can't open user file\n";
while ( <USER> )
{
   chomp;
   next if /^\s+/;
   next if /^#/;
   push(@user, $_);
}
close(USER);

## Calculate the number of user's crontab job
opendir(DIR, "$program_dir") || die "ERROR:Can't open program dir\n";
while( defined( my $filename = readdir(DIR) ) )
{
   next if ($filename eq '.' || $filename eq '..');
   next if ($filename eq 'crontab_ssh.pl');
   next if ($filename eq 'crontab_ssh1.pl');
   next if ($filename eq 'crontab_ssh_host.txt');
   next if ($filename eq 'crontab_ssh_user.txt');
   push(@user_crontab, $filename);
}
close(DIR);

##################################################
## Deploy the crontab job task to each host ##
##################################################
if (@user_crontab == @user)
{
   foreach my $host (@host)
   {
      scp_key($host);
     
      foreach my $user (@user)
      {
         `/usr/bin/scp $program_dir/crontab_$user root@"$host":$cron_dir/$user`;
         `ssh root@"$host" chown root:cron $cron_dir/$user`;
         `ssh root@"$host" chmod 600 $cron_dir/$user`;
      }
   }
}
else
{
   print "ERROR:defined users from crontab_ssh_user.txt and defined crontab_\$user counters are not the same\n";
   exit 1;
}

sub scp_key
{
   my $target_host = shift;
   my $tmp_dir = '/tmp';
   my $command;
   $command = "/usr/bin/cat ~/.ssh/id_rsa.pub > $tmp_dir/key";
   `LANG=C $command`;
   $command = "/usr/bin/scp -q $tmp_dir/key root\@$target_host:~/.ssh/authorized_keys2";
   `LANG=C $command`;
   $command = "/usr/bin/rm $tmp_dir/key 2>/dev/null";
   `LANG=C $command`;
 
   return($target_host);
}

================================================================
crontab_ssh_host檔案內容格式:
## Insert the host name or IP address
10.199.131.238
10.199.131.239
================================================================
crontab_ssh_user檔案內容格式:
## Insert the user name 
tommy
jammy
================================================================
crontab_user1檔案內容格式:
45 2 * * 0 /usr/lib/spell/compress
45 23 * * * ulimit 5000; /usr/lib/smdemon.cleanu > /dev/null 
================================================================
crontab_user2檔案內容格式:
45 2 * * 0 /usr/lib/spell/compress
================================================================