Linux-执行校验脚本

 

#!/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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值