No menu items!
No menu items!
More

    Bash script tự động check số liệu Covid hàng ngày và gửi telegram khi có thay đổi

    Bài viết này mình chia sẻ 1 script viết bằng bash shell để check và gửi thông báo về số liệu dịch covid19 về telegram khi có thay đổi.

    Script đơn giản như sau:

    #!/usr/bin/env bash
    
    old_socanhiemtrongngay=''
    old_tongsocatuvong=''
    old_socakhoibenh=''
    
    sendtelegram(){
    		  token=1918522332:AAHSkYIsPiY3LeHX8t5f1QLO4y7RtvociUY
    		    chatid=-436448570
    		      URL="https://api.telegram.org/bot$token/sendMessage"
    		        curl -s -X POST $URL -d chat_id=$chatid -d text="$message" >> /dev/null
    		}
    
    	  covid-check(){
    	  date_now=$(date +"%H:%M:%S %d/%m/%Y")
    
    	  curl https://disease.sh/v3/covid-19/countries/vietnam | jq '.' > /root/covid-info.txt
    	  tongsocanhiem=$(cat /root/covid-info.txt | jq '."cases"')
    	  socanhiemtrongngay=$(cat /root/covid-info.txt | jq '."todayCases"')
    	  tongsocatuvong=$(cat /root/covid-info.txt | jq '."deaths"')
    	  socakhoibenh=$(cat /root/covid-info.txt | jq '."recovered"')
    
    	  message=$(echo -e "\nThống kê số liệu Covid-19 tại Việt Nam\nTổng số ca nhiễm: $tongsocanhiem\nSố ca nhiễm trong ngày: $socanhiemtrongngay\nSố ca tử vong: $tongsocatuvong\nSố ca khỏi bệnh: $socakhoibenh\nThời gian cập nhật: $date_now")
    
    	  if [[ $socanhiemtrongngay != $old_socanhiemtrongngay || $tongsocatuvong != $old_tongsocatuvong || $socakhoibenh != $old_socakhoibenh ]];then
    		  old_socanhiemtrongngay=$socanhiemtrongngay
    		  old_tongsocatuvong=$tongsocatuvong
    		  old_socakhoibenh=$socakhoibenh
    		  sendtelegram
    	  fi
    
      }
    while :
    do
    	covid-check
    	sleep 3600
    done

    Bạn chỉ cần thay đổi token và chatid telegram của bạn là xong.

    Bài viết gần đây

    spot_img

    Related Stories

    Leave A Reply

    Please enter your comment!
    Please enter your name here

    Đăng ký nhận thông tin bài viết qua email