monitor.lib 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. monitor_set(){
  2. local jqcmd="$1"
  3. local file="$2"
  4. local json=$(cat "${file}"|jq "${jqcmd}" -c)
  5. echo "${json}" > "${file}" # centos下禁止cat和>同时执行,在ubuntu下会导致文件变空。故拆成两句,避免输入输出流冲突
  6. }
  7. monitor_get(){
  8. local jqcmd="$1"
  9. local file="$2"
  10. cat "${file}"|jq "${jqcmd}" -c
  11. }
  12. # 太复杂了,弃用!上面的get和set够用
  13. # moniterdb set "path.to.leaf" "value"
  14. # moniterdb get "path.to.leaf"
  15. # moniterdb all
  16. # moniterdb clear
  17. # moniterdb init "...json..."
  18. moniterdb(){
  19. local moniterFile=''
  20. while getopts "f:s:" optname; do
  21. case "$optname" in
  22. f)
  23. moniterFile="${OPTARG}"
  24. ;;
  25. *)
  26. echo 'error arg option: -${optname}.'
  27. return
  28. ;;
  29. esac
  30. done
  31. local action=''
  32. case $1 in
  33. init)
  34. ;;
  35. set)
  36. ;;
  37. get)
  38. ;;
  39. all)
  40. ;;
  41. clear)
  42. ;;
  43. *)
  44. echo "error monitordb action $1"
  45. return
  46. ;;
  47. esac
  48. }