check_hls_backup.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. if [[ $# -lt 2 ]]; then
  2. echo "Usage: $0 <hls0> <hls1> [keep_ts]"
  3. echo " keep_ts to keep the download ts, default is off"
  4. echo "For example:"
  5. echo " $0 http://192.168.1.137:1980/hls/live/stone/live.m3u8 http://192.168.1.137:1984/hls/live/stone/live.m3u8"
  6. echo " $0 http://192.168.1.137:1980/hls/live/livestream/live.m3u8 http://192.168.1.137:1984/hls/live/livestream/live.m3u8"
  7. echo " $0 http://ossrs.net:1984/hls/live/livestream/live.m3u8 http://ossrs.net:1996/hls/live/livestream/live.m3u8"
  8. exit 1
  9. fi
  10. hls0=$1
  11. hls1=$2
  12. keep_ts=NO
  13. if [[ $# -gt 2 ]]; then
  14. keep_ts=YES
  15. fi
  16. #echo "check hls backup of $hls0 vs $hls1, keep_ts=$keep_ts"
  17. hls0_tss=`curl $hls0 2>/dev/null |grep "\.ts"`
  18. hls1_tss=`curl $hls1 2>/dev/null |grep "\.ts"`
  19. hls0_prefix=`dirname $hls0`
  20. hls1_prefix=`dirname $hls1`
  21. work_dir="./hbt_temp_`date +%s`"
  22. md5_tool="md5"
  23. `md5sum --version >/dev/null 2>&1` && md5_tool="md5sum"
  24. #echo "use md5 tool: $md5_tool"
  25. CHECKED=NO
  26. OK=YES
  27. for ts in $hls0_tss; do
  28. match=NO
  29. for ts1 in $hls1_tss; do
  30. if [[ $ts == $ts1 ]]; then
  31. #echo "check ts $ts"
  32. match=YES
  33. break
  34. fi
  35. done
  36. #echo "check ts $ts, match=$match"
  37. if [ $match = NO ]; then
  38. echo "skip $ts"
  39. continue
  40. fi
  41. ts0_uri=$hls0_prefix/$ts
  42. ts1_uri=$hls1_prefix/$ts
  43. ts0_tmp=$work_dir/hls0/`basename $ts`
  44. ts1_tmp=$work_dir/hls1/`basename $ts`
  45. #echo "start check $ts0_uri($ts0_tmp) vs $ts1_uri($ts1_tmp)"
  46. mkdir -p `dirname $ts0_tmp` &&
  47. curl $ts0_uri >$ts0_tmp 2>/dev/null &&
  48. ret=$?; if [[ $ret -ne 0 ]]; then echo "download $ts0_uri to $ts0_tmp failed. ret=$ret"; exit $ret; fi
  49. mkdir -p `dirname $ts1_tmp` &&
  50. curl $ts1_uri >$ts1_tmp 2>/dev/null &&
  51. ret=$?; if [[ $ret -ne 0 ]]; then echo "download $ts1_uri to $ts1_tmp failed. ret=$ret"; exit $ret; fi
  52. if [[ $md5_tool == "md5" ]]; then
  53. ts0_cs=`$md5_tool $ts0_tmp|awk '{print $4}'`
  54. else
  55. ts0_cs=`$md5_tool $ts0_tmp|awk '{print $1}'`
  56. fi
  57. #echo "hls0: md5sum($ts0_tmp)=$ts0_cs"
  58. if [[ $md5_tool == "md5" ]]; then
  59. ts1_cs=`$md5_tool $ts1_tmp|awk '{print $4}'`
  60. else
  61. ts1_cs=`$md5_tool $ts1_tmp|awk '{print $1}'`
  62. fi
  63. #echo "hls1: md5sum($ts1_tmp)=$ts1_cs"
  64. if [[ $ts0_cs != $ts1_cs ]]; then
  65. echo "$ts0_uri($ts0_cs) not equals to $ts1_uri($ts1_cs)"
  66. OK=NO
  67. fi
  68. CHECKED=YES
  69. done
  70. if [ $keep_ts = NO ]; then
  71. #echo "clenaup work dir $work_dir"
  72. rm -rf $work_dir
  73. else
  74. echo "keep work dir $work_dir"
  75. fi
  76. #echo "====================================================="
  77. if [[ $OK = YES && $CHECKED = YES ]]; then
  78. echo "OK"
  79. exit 0
  80. else
  81. echo "FAILED"
  82. exit 1
  83. fi
  84. exit 0