shell脚本实现自动化安装linux版本的loadrunner agent(centos6.8)
#!/bin/bash #Centos6下安装LoadRunner负载机 #@author Agoly #@date 20171101 #@source 高级测试技术交流圈:655580380 yum -y install expect PASSWD13="123456" PASSWD99="Hhly2017" folder="/root/qumf" lrfolder="/opt/HP/HP_LoadGenerator" file="/root/qumf/LR11Generator.sh" #判断/root/qumf目录是否存在 # -d 参数判断 $folder 是否存在 if [[ ! -d "$folder" ]]; then mkdir "$folder" echo "************$folder **file make successfully************" else echo "************$folder **file exsit************" fi #判断安装文件/root/qumf/LR11Generator.sh是否存在 # -f 参数判断 $file 是否存在 if [[ ! -f "$file" ]]; then echo "************${file} **file is not exsit************" expect -c " spawn scp -r root@192.168.10.99:/root/qumf/LR11Generator.sh /root/qumf/ expect { \"*assword\" { set timeout 300; send \"$PASSWD99\r\"; } \"yes/no\" { send \"yes\r\"; exp_continue;} } expect eof" #scp -r root@192.168.12.13:/root/qumf/lr11_load_gennerators_linux/ /root/qumf/ else echo "************${file} **file exist************" fi #判断负载linux上是否安装了/opt/HP/HP_LoadGenerator # -d 参数判断 $lrfile 是否存在 if [[ ! -d "$lrfolder" ]]; then echo "************$lrfolder **is not installed************" expect -c " spawn scp -r root@192.168.12.13:/root/qumf/lr11_load_gennerators_linux/ /root/qumf/ expect { \"*assword\" { set timeout 300; send \"$PASSWD13\r\"; } \"yes/no\" { send \"yes\r\"; exp_continue;} } expect eof" else echo "************$lrfolder **has installed************" exit 1 fi echo $folder #mv /root/LR11Generator.sh $folder yum -y install libstdc++.so.5 yum -y install libstdc++.i686* #systemctl stop iptables #systemctl stop firewalld service iptables stop cd /root/qumf/ chmod 755 lr11_load_gennerators_linux/* cd lr11_load_gennerators_linux/ chmod -R 777 Linux/ cd Linux/ expect -c " spawn /root/qumf/lr11_load_gennerators_linux/Linux/installer.sh expect \"* ] :\" send \"n\r\" expect \"* ] :\" send \"a\r\" expect \"* ] :\" send \"i\r\" expect \"* ] :\" send \"f\r\" expect eof" #expect -c " #spawn /root/qumf/lr11_load_gennerators_linux/Linux/installer.sh #expect { # \"*]*\" # { # send \"n\r\" # send \"a\r\" # send \"i\r\" # send \"f\r\" # } #} #expect eof" useradd -g 0 -s /bin/bash loadrunner expect -c " spawn passwd loadrunner expect \"New password:\" send \"$PASSWD99\r\" expect \"Retype new password:\" send \"$PASSWD99\r\" expect eof" cd /opt/HP/HP_LoadGenerator touch /opt/HP/HP_LoadGenerator/env.sh cat > /opt/HP/HP_LoadGenerator/env.sh <<EOF #!/bin/bash export PRODUCT_DIR=/opt/HP/HP_LoadGenerator export M_LROOT=\$PRODUCT_DIR export LD_LIBRARY_PATH=\$M_LROOT/bin:\$M_LROOT/lib:/usr/lib:/usr/lib64 export DISPLAY='0.0' export PATH=\$PATH:\$M_LROOT/bin EOF sed -i '$a source /opt/HP/HP_LoadGenerator/env.sh' /etc/profile expect -c " spawn su - loadrunner expect \"$\" send \"cd /opt/HP/HP_LoadGenerator/bin\r\" expect \"$\" send \"./m_daemon_setup start\r\" expect \"$\" send \"ps -ef|grep m_agent_daemon | grep -v grep\r\" interact expect eof"
作者:Agoly 出处:https://www.cnblogs.com/qmfsun/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 如果文中有什么错误,欢迎指出。以免更多的人被误导。 |