Linux-执行校验脚本

版权声明:Summer https://blog.csdn.net/csdnyanglei/article/details/83056546
#!/bin/bash
#function       : 1 检查文件是否存在 2 执行文件 3 支持单个或多个一起
#file name      :
#author         :

#放置jar包的目录
root_path="./jar/"
profiles_active="test_env"
loaded_jar_info="./app.properties"
##############

#提醒
warn_info(){
  echo "$(date +"%Y-%m-%d %T"):$1"
}

warn_info2(){
 echo -e "\033[36m ${1} \033[0m \n"
}

#打印位置
jar_location(){
  echo ${root_path}${1}
}

#所有文件校验
all_check(){ 
  arr_files=$(ls ${root_path})
  for key in $(cat "${loaded_jar_info}"|cut -d ':' -f 1 )
  do
    if [ $(echo "${arr_files[@]}" | grep -c "${key}") -ne 1 ];then
      warn_info "==>error:${key},this file is not exist..."
      exit
    fi
  done
  warn_info "all check finished..."
}

#单个文件校验
simple_check(){
  file_name=${1}
  arr_files=$(ls ${root_path})
  
  if [ $(echo "${arr_files[@]}" | grep -c "${file_name}") -ne 1 ];then
      warn_info "==>error:${file_name},this file is not exist..."
      exit
  fi
  warn_info "${file_name} file check finished..."
}

#加载jar包
load_app(){
 jar_name=${1}
 port=${2}
 warn_info "======>execute new jar,jar_name:${jar_name},${port}" 
}

#分发app
distribute_invoke(){
  for key in $(cat "${loaded_jar_info}")
  do
    this_file=$(echo ${key}|cut -d ':' -f1)
    this_port=$(echo ${key}|cut -d ':' -f3)
    load_app "${this_file}" "${this_port}"
  done
}

mymain(){ 
 echo
 warn_info2 "welcome to use loading sh"
 
 while true
 do
  awk -F: 'BEGIN {count=0;}  { print "\n=>follows files list:";count++ } \
               { printf "%3d:%-50s:%5d\n",NR,$1,$3} \
           END {printf "\033[36m files list count:%5d\033[0m\n",count} ' \
               "${loaded_jar_info}" 
  warn_info2 "you can input [choice sequence],[all],[quit],"
  read -p "$(warn_info2 "Enter your choice sequence:")" user_choice

  case $user_choice in 
         [1-9]) 
           choiced_file=$(sed -n "${user_choice}p" app.properties |cut -d ':' -f1 )
           choiced_port=$(sed -n "${user_choice}p" app.properties |cut -d ':' -f3 )
           simple_check "${choiced_file}"
           load_app "${choiced_file}" "${choiced_port}" 
         ;; 
         all) 
           all_check
           distribute_invoke 
           exit
         ;; 
         quit|q)
           warn_info2 "bye"
           exit
         ;;
         *) 
           echo "Ignorant" 
         ;; 
  esac
 done 
}

mymain

app.properties

AAAAAA.jar::8300
BBBBBB.jar::8301
CCCCCC.jar::9000

猜你喜欢

转载自blog.csdn.net/csdnyanglei/article/details/83056546