vicf

measure nordvpn server status

May 23rd, 2020
19,420
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/bash
  2. today=$(date +%Y%m%d)
  3. log="$HOME/nordvpn.log-${today}"
  4. OIFS=$IFS
  5. IFS=$'\n'
  6. dead=0
  7. live=0
  8.  
  9. while read -r ovpn ; do
  10.     vpnip=$(awk '/^remote [0-9][0-9]*\..*/{print $2}' $ovpn)
  11.     server=$(echo $ovpn | cut -d"/" -f4 | cut -d"." -f1)
  12.     ping -w3 "$vpnip"
  13.     RET=$?
  14.     if [ $RET -gt 0 ] ; then
  15.         echo "$server dead." | tee -a "$log"
  16.         ((dead++))
  17.     else
  18.         echo "$server can be connected." | tee -a "$log"
  19.         ((live++))
  20.     fi
  21.  
  22. done < <(ls /etc/openvpn/*.udp*.ovpn | awk '{print $NF}')
  23.  
  24. printf '\n\n\n' >> "$log"
  25. echo "Total: $((dead+live)) server" | tee -a "$log"
  26. echo "Can be contected: $live" | tee -a "$log"
  27. echo "Cannot be connect: $dead" | tee -a "$log"
  28.  
  29. unset IFS
  30. IFS=$OIFS
  31.  
  32. exit 0
RAW Paste Data