py_mysql.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/bash
  2. #. /opt/app/bi-app/energy/dayTask/config.sh
  3. if [ -n "$2" ] ;then
  4. echo "如果是输入的日期按照取输入日期"
  5. do_date=$2
  6. startSec=`date -d "$do_date" "+%s"`
  7. echo $startSec
  8. current_day=`date -d "@$startSec" "+%Y-%m-%d"`
  9. one_day_ago=`date -d "$current_day yesterday" +%Y%m%d`
  10. start_time=`date -d "-1 day $current_day" +%Y%m%d`000000
  11. end_time=`date -d "0 day $current_day" +%Y%m%d`000000
  12. energy_start_time=`date -d "-2 day $current_day" +%Y%m%d`000000
  13. energy_end_time=`date -d "-1 day $current_day" +%Y%m%d`160000
  14. else
  15. echo "====没有输入数据的日期,取当前时间的前一天===="
  16. start_time=`date -d "-1 day" +"%Y%m%d"`000000
  17. end_time=`date -d "0 day" +"%Y%m%d"`000000
  18. energy_start_time=`date -d "-2 day" +"%Y%m%d"`160000
  19. energy_end_time=`date -d "-1 day" +"%Y%m%d"`160000
  20. fi
  21. echo "start_time:" $start_time
  22. echo "end_time:" $end_time
  23. echo "energy_start_time:" $energy_start_time
  24. echo "energy_end_time:" $energy_end_time
  25. #
  26. # 11301 CO2
  27. # 11401 PM2.5
  28. # 11305 甲醛
  29. # 11101 温度
  30. # 11201 湿度
  31. ## 能源数据
  32. energy_hbase_to_mysql(){
  33. /usr/local/bin/python3 /opt/app/python_transfer/start_mysql.py 10101 --start_time $start_time --end_time $end_time
  34. }
  35. ## CO2
  36. co2_hbase_to_mysql(){
  37. /usr/local/bin/python3 /opt/app/python_transfer/start_mysql.py 11301 --start_time $start_time --end_time $end_time
  38. }
  39. ## PM2.5
  40. pm25_hbase_to_mysql(){
  41. /usr/local/bin/python3 /opt/app/python_transfer/start_mysql.py 11401 --start_time $start_time --end_time $end_time
  42. }
  43. ## 甲醛
  44. hcho_hbase_to_mysql(){
  45. /usr/local/bin/python3 /opt/app/python_transfer/start_mysql.py 11305 --start_time $start_time --end_time $end_time
  46. }
  47. ## 温度
  48. temperature_hbase_to_mysql(){
  49. /usr/local/bin/python3 /opt/app/python_transfer/start_mysql.py 11101 --start_time $start_time --end_time $end_time
  50. }
  51. ## 湿度
  52. humidity_hbase_to_mysql(){
  53. /usr/local/bin/python3 /opt/app/python_transfer/start_mysql.py 11201 --start_time $start_time --end_time $end_time
  54. }
  55. case $1 in
  56. "all")
  57. energy_hbase_to_mysql
  58. co2_hbase_to_mysql
  59. pm25_hbase_to_mysql
  60. hcho_hbase_to_mysql
  61. temperature_hbase_to_mysql
  62. humidity_hbase_to_mysql
  63. ;;
  64. "energy")
  65. energy_hbase_to_mysql
  66. ;;
  67. "co2")
  68. co2_hbase_to_mysql
  69. ;;
  70. "pm25")
  71. pm25_hbase_to_mysql
  72. ;;
  73. "hcho")
  74. hcho_hbase_to_mysql
  75. ;;
  76. "temperature")
  77. temperature_hbase_to_mysql
  78. ;;
  79. "humidity")
  80. humidity_hbase_to_mysql
  81. ;;
  82. esac