common_func.sh 1.4 KB

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