utils_func.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. if [ $last_status -eq 0 ]; then
  49. echo -e "\033[33m Run successfully with command - ${run_command}! \033[0m" | tee -a ${run_log}
  50. else
  51. echo -e "\033[33m Run failed with command - ${run_command}! \033[0m" | tee -a ${run_log}
  52. fi
  53. }