update.sh
#!/bin/sh
#$1:install path $2:hub link ip and port
install_path=$1
if [ -z "$install_path" ]
then
	install_path=$HOME
fi
UUID=$2
HostID=$3
HubIpPort=$4
install_dir="${install_path}/agent60"
src_dir="agent60"
#flat to success
agent_flag=1
configPara_flag=1
crontab_flag=1
nowtime=`date +"%Y-%m-%d %T"`
echo $nowtime "agent60 install begin" 
echo "===================================================="
echo "set environment variables"
if [ -f $HOME/.bash_profile ]
then
        . $HOME/.bash_profile
elif [ -f $HOME/.profile ]
then        
        . $HOME/.profile
elif [ -f $HOME/.bashrc ]
then
        . $HOME/.bashrc
fi
OS_TYPE=`uname`
if [ $OS_TYPE = "AIX" ]
then
	export LIBPATH=.:../lib:$LIBPATH
	export LD_LIBRARY_PATH=.:../lib:$LD_LIBRARY_PATH
elif [ $OS_TYPE = "HP-UX" ]
then
	export SHLIB_PATH=.:../lib:$SHLIB_PATH
	export LD_LIBRARY_PATH=.:../lib:$LD_LIBRARY_PATH
elif [ $OS_TYPE = "SunOS" ]
then
	LD_LIBRARY_PATH=.:../lib:$LD_LIBRARY_PATH
	export LD_LIBRARY_PATH
else
	export LD_LIBRARY_PATH=.:../lib:$LD_LIBRARY_PATH
fi
#stop agent60
pid=`ps -ef | grep "agent60 -m" | grep -v "grep" |awk '{print $2}'`
if [ $pid ]
then
 kill -9 $pid
fi
sleep 1 
#install 
umask 022
if [ -f $install_dir ]
then
	rm -f $install_dir
fi
if [ ! -d $install_dir ]
then
	cp -r $src_dir $install_dir
else
	rm -f $install_dir/bin/agent60
	
	cp $src_dir/bin/agent60 $install_dir/bin/
	cp -r $src_dir/config/* $install_dir/config/
	if [ -d $src_dir/lib ]
	then
		cp -r $src_dir/lib/* $install_dir/lib
	fi
fi
chmod -R 755 $install_dir
#dir is exist
if [ ! -d $install_dir ]
then
	echo "$install_dir create failed"
	echo "agent60 install failed"
	exit
else
	if [ ! -d $install_dir/bin ]
	then
		echo "$install_dir/bin create failed"
		echo "agent60 install failed"
		exit
	fi
fi
#edit agent.int parameter
if [ x${UUID} != x ]
then
	sed  "s/UUID.*/UUID=${UUID}/" $install_dir/config/agent.ini > inst_agent.ini.bak
	mv -f inst_agent.ini.bak $install_dir/config/agent.ini
	
	#success?
	line=`cat  $install_dir/config/agent.ini | grep "UUID=${UUID}" | wc -l`
	if [ $line != 0 ]
	then
		echo "$install_dir/config/agent.ini UUID parameter update success"
	else
		configPara_flag=0
		echo "$install_dir/config/agent.ini UUID parameter update failed"
		exit
	fi
fi
#if [ x${HostID} != x ]
#then
	sed  "s/HostID.*/HostID=${HostID}/" $install_dir/config/agent.ini > inst_agent.ini.bak
	mv -f inst_agent.ini.bak $install_dir/config/agent.ini
	
	#success?
	line=`cat  $install_dir/config/agent.ini | grep "HostID=${HostID}" | wc -l`
	if [ $line != 0 ]
	then
		echo "$install_dir/config/agent.ini HostID parameter update success"
	else
		configPara_flag=0
		echo "$install_dir/config/agent.ini HostID parameter update failed"
		exit
	fi
#fi
if [ x${HubIpPort} != x ]
then
	sed  "s/HubIpPort.*/HubIpPort=${HubIpPort}/" $install_dir/config/agent.ini > inst_agent.ini.bak
	mv -f inst_agent.ini.bak $install_dir/config/agent.ini
	
	#success?
	line=`cat  $install_dir/config/agent.ini | grep "HubIpPort=${HubIpPort}" | wc -l`
	if [ $line != 0 ]
	then
		echo "$install_dir/config/agent.ini HubIpPort parameter update success"
	else
		configPara_flag=0
		echo "$install_dir/config/agent.ini HubIpPort parameter update failed"
		exit
	fi
fi
#agent60?
if [ ! -f $install_dir/bin/agent60 ]
then
	agent_flag=0
	echo "${install_dir}/bin path agent60 not exit,install failed"
	exit
else
	cd $install_dir/bin
	./agent60 -v
	exeRet=$?
	if [ $exeRet != 0 ]
	then
		agent_flag=0
		echo "agent60 exe error,install failed"
		exit
	fi
fi
#install crontab
cd $install_path
crontab_bocs=`crontab -l |grep -w "agent60" |grep -w "monitor.sh"|grep -v grep`
if [ "${crontab_bocs}" = "" ]
then
    crontab -l > crontab_bocs.list
    echo "0,10,20,30,40,50 * * * * sh ${install_dir}/bin/monitor.sh ${install_dir}/bin>/dev/null 2>&1" >> crontab_bocs.list
    crontab crontab_bocs.list
    rm -f crontab_bocs.list
	
	line=`crontab -l |grep -w "agent60" |grep -w "monitor.sh"| grep -v grep  |wc -l`
	if [ $line = 0 ]
	then
        crontab_flag=0
		echo "agent60 crontab monitor add failed"
	else
		echo "agent60 crontab monitor add success"
	fi
fi
#run 
if [ "${agent_flag}${configPara_flag}${crontab_flag}" = "111" ]
then
	sh ${install_dir}/bin/monitor.sh ${install_dir}/bin
	sleep 1
	pid=`ps -ef | grep "agent60 -m" | grep -v "grep" |awk '{print $2}'`
	if [ $pid ]
	then
		echo "agent60 run success,process id: ${pid}"
		echo "all install success"
	else
		echo "agent60 run failed"
	fi
else
	echo "agent60 install failed"
fi
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号