utils_func.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. function func_parser_key(){
  3. strs=$1
  4. echo ${strs%%:*}
  5. }
  6. function func_parser_value(){
  7. strs=$1
  8. echo ${strs#*:}
  9. }
  10. function func_set_params(){
  11. key=$1
  12. value=$2
  13. if [ ${key}x = "null"x ];then
  14. echo " "
  15. elif [[ ${value} = "null" ]] || [[ ${value} = " " ]] || [ ${#value} -le 0 ];then
  16. echo " "
  17. else
  18. echo "${key}=${value}"
  19. fi
  20. }
  21. function func_parser_params(){
  22. strs=$1
  23. IFS=":"
  24. array=(${strs})
  25. key=${array[0]}
  26. tmp=${array[1]}
  27. IFS="|"
  28. res=""
  29. for _params in ${tmp[*]}; do
  30. IFS="="
  31. array=(${_params})
  32. mode=${array[0]}
  33. value=${array[1]}
  34. if [[ ${mode} = ${MODE} ]]; then
  35. IFS="|"
  36. #echo $(func_set_params "${mode}" "${value}")
  37. echo $value
  38. break
  39. fi
  40. IFS="|"
  41. done
  42. echo ${res}
  43. }
  44. function status_check(){
  45. last_status=$1 # the exit code
  46. run_command=$2
  47. run_log=$3
  48. model_name=$4
  49. log_path=$5
  50. if [ $last_status -eq 0 ]; then
  51. echo -e "\033[33m Run successfully with command - ${model_name} - ${run_command} - ${log_path} \033[0m" | tee -a ${run_log}
  52. else
  53. echo -e "\033[33m Run failed with command - ${model_name} - ${run_command} - ${log_path} \033[0m" | tee -a ${run_log}
  54. fi
  55. }