#!/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";