Advertisement
gpz1100

Untitled

Nov 18th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Set Warnings
  4. TEMPS=50
  5. VOLTS=4
  6. TX=3
  7. RX="-25"
  8. BIAS=15
  9.  
  10. # Set Telegram
  11. #BOT_TOKEN="TOKEN"
  12. #CHAT_ID="ID"
  13.  
  14. # Telegram send message
  15. #send_telegram_message() {
  16. # message="$1"
  17. # curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \
  18. # -H 'Content-Type: application/json' \
  19. # -d '{"chat_id":"'"$CHAT_ID"'", "text":"'"$message"'", "parse_mode": "html", "protect_content": true}' \
  20. # >/dev/null 2>&1
  21. #}
  22.  
  23. # Router URL
  24. LOGIN_URL="http://192.168.1.1/boaform/admin/formLogin?username=admin&password=admin&save=Login&submit-url=%2Fadmin%2Flogin.asp"
  25. STATUS_URL="http://192.168.1.1/status_pon.asp"
  26.  
  27. # Fetch the content of the status page using the authenticated session
  28. curl -s "$LOGIN_URL" > /dev/null
  29.  
  30. # Fetch the content of the status page using the authenticated session
  31. html_content=$(curl -s "$STATUS_URL")
  32.  
  33. # Define an array of the parameters you want to extract
  34. #parameters=("Temperature" "Voltage" "Tx Power" "Rx Power" "Bias Current")
  35.  
  36. # Loop through the parameters
  37. #for param in "${parameters[@]}"; do
  38. echo
  39.  
  40. for param in "Temperature" "Tx Power" "Rx Power" "Voltage" "Bias Current"; do
  41. # Use grep to find the line with the parameter and then use sed to extract the value
  42. value=$(echo "$html_content" | grep -A1 "$param" | tail -n1 | sed -n 's/.*>\(.*\)<\/.*/\1/p')
  43.  
  44. # Extract the numerical part of the value (including negative sign)
  45. numerical_value=$(echo $value | awk '{print $1}')
  46.  
  47. # Extract the unit of the value
  48. unit=$(echo $value | awk '{print $2}')
  49.  
  50. # Round off the value to 2 decimal points
  51. rounded_value=$(printf "%.2f" $numerical_value)
  52.  
  53. echo $param: $rounded_value $unit
  54.  
  55. # Add individual checks for each parameter
  56. # if [ "$param" == "Temperature" ] && (( $(echo "$rounded_value > $TEMPS" | bc -l) )); then
  57. # send_telegram_message "<b>**WARNING**</b> \n <b>$param:</b> $rounded_value $unit"
  58. # elif [ "$param" == "Voltage" ] && (( $(echo "$rounded_value > $VOLTS" | bc -l) )); then
  59. # send_telegram_message "<b>**WARNING**</b> \n <b>$param:</b> $rounded_value $unit"
  60. # elif [ "$param" == "Tx Power" ] && (( $(echo "$rounded_value > $TX" | bc -l) )); then
  61. # send_telegram_message "<b>**WARNING**</b> \n <b>$param:</b> $rounded_value $unit"
  62. # elif [ "$param" == "Rx Power" ] && (( $(echo "$rounded_value < $RX" | bc -l) )); then
  63. # send_telegram_message "<b>**WARNING**</b> \n <b>$param:</b> $rounded_value $unit"
  64. # elif [ "$param" == "Bias Current" ] && (( $(echo "$rounded_value > $BIAS" | bc -l) )); then
  65. # send_telegram_message "<b>**WARNING**</b> \n <b>$param:</b> $rounded_value $unit"
  66. # fi
  67. done
  68.  
  69.  
  70.  
  71. echo
  72. echo
  73.  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement