py_mysql.sh 3.1 KB

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