shell编程 tomcat的shell脚本自动化安装

#! /bin/bash
main_path=/usr/local/tomcat
install_name=apache-tomcat-9.0.10.tar.gz
install_path=/usr/local/tomcat/
env_fun()
{
echo "---检测本机环境----"

username=`ps -ef|grep apache-tomcat-9.0.10 |grep -v grep`       //该命令判断服务是否启动,从而判断是否安装了tomcat

                                                                                                        逻辑上不是这样判断。无奈没有方法判断本机是否安装

                                                                                                        服务,而不是启动服务。有方法欢迎交流

        if [[ -z $username ]]; then                                                    //-z判断是否空字符串
                echo "tomcat不存在"
                return 10
        else
                echo "tomcat存在"
                return 12
        fi
}
install_fun(){
echo "建立tomcat文件夹"
mkdir -p /usr/local/tomcat
cd $main_path
echo "正在下载。请稍等..."
wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.10/bin/apache-tomcat-9.0.10.tar.gz
echo "正在解压,请稍等..."
cd /usr/local/tomcat
tar -zxvf $install_name
echo "安装完成"
rm -rf /usr/local/tomcat/apache-tomcat-9.0.10.tar.gz                //删除安装包,不然下次安装多一个安装包.1.2.3以此类推
echo "move tar packet over"
}
main(){
echo "***安装tomcat***"
sleep 1
env_fun
re=$?
if [ 10 -eq $re ] ;then
        install_fun
else
        echo "tomcat已存在,不需要安装"
fi
}
main
exit 0

你可能感兴趣的:(shell)