交互式shell脚本编程3

#! /bin/shell


#==========================================================================================
# author:zhaoshuangjian
# date  :2023-02-24
# slogan:追求的不仅是技术,更是梦想!
#==========================================================================================







#==========================================================================================
# 第一种方式 函数式调用
#==========================================================================================

manager() {
  if [[ -d "$managerfolder" ]]; then

    # stop manager process
    sh "$managerfolder/bin/shutdown.sh"

    # delete manager folder
    rm -rf "$managerfolder"

    # tar manager folder
    tar -zxvf "$managerpath/tongdsp.manager-3.1.0.tar.gz"

    # copy license.dat
    cp -r "$managerpath/license.dat" "$managerfolder"

    # start manager  process
    sh "$managerfolder/bin/startup.sh"

    # 查询manager进程
    process=`ps -ef|grep "tongdsp.manager-3.1.0"|grep -v grep | awk '{print $2}'`
    # 如果进程存在,说明启动成功
    if [[ -n "$process" ]]; then
      # manager启动成功
      echo "manager $process process is running !"
    else
      # manager启动失败
      echo "manager $process process is fail !"
    fi
  fi
}


zookeeper() {
  # 查询进程
  # process=`ps -ef | grep "zookeeper01" | grep -v grep | awk '{print $2}'`

  # 如果进程存在,则结束该进程
  # if [[ -n "$process" ]]; then
  #   echo "zookeeper process id is $process"
  #   kill $process
  # fi

  # 启动zookeeper
  $zookeeperpath/zkServer.sh restart

  # 查询进程
  process=`ps -ef | grep "zookeeper01" | grep -v grep | awk '{print $2}'`

  # 如果进程存在,说明启动成功
  if [[ -n "$process" ]]; then
    # zookeeper启动成功
    echo "zookeeper $process process is running !"
  else
    # zookeeper启动失败
    echo "zookeeper $process process is fail !"
  fi
}

OPTION=$(whiptail --title "zhaoshuangjian Menu Dialog" --menu "Choose your option" 15 60 4 \
"1" "restart zookeeper" \
"2" "manager kill-tar-start" \
"3" "预留" \
"4" "预留"  3>&1 1>&2 2>&3)




managerpath=/home/zhaosj/dsp/
managerfolder="$managerpath/tongdsp.manager-3.1.0/"
zookeeperpath=/home/zhaosj/zookeeper01/bin/
exitstatus=$?
if [ $exitstatus = 0 ]; then

  if [[ $OPTION = 1 ]]; then
    
    zookeeper


  elif [ $OPTION == 2 ];then

    manager

  fi

else
    echo "You chose Cancel."
fi




#==========================================================================================
# 第二种方式
#==========================================================================================

# choose_environment() {
#     # 重新选择
#     reselect=${1}
#     if [ $reselect == 0 ];then
#         echo '请选择要操作的环境: '
#     elif [ $$reselect == 1 ];then
#         echo '请重新选择要操作的环境: '
#   fi
#     echo '1.开发环境'
#     echo '2.测试环境'
#   echo 'q.结束'
#   # 获取用户的输入
#     read -p '请输入序号, 选择环境: ' -n 1 environmentnum
#   echo '\n'
#   # 这里注意,判断空必须加双引号,双引号识别为没有内容;主要处理没有输入指令直接回车
#   if [ -z "$environmentnum" ];then
#     choose_environment 0
#     elif [ $environmentnum == 1 ];then
#         echo '进入开发环境操作'
#     elif [ $environmentnum == 2 ];then
#         echo '进入测试环境操作'
#   elif [ $environmentnum == 'q' ];then
#     echo '欢迎再次使用'
#     # 结束脚本执行
#     exit 1
#     else 
#         echo '不支持的序号'
#     echo $environmentnum
#     choose_environment 1
#     fi
# }

# choose_environment 0



#==========================================================================================
# 生活充满了选择,而生活的态度就是一切
#==========================================================================================

你可能感兴趣的:(五,服务器,linux,java,服务器)