samedi 16 juillet 2016

shell if statement always returning true

I want to check if my VPN is connected to a specific country. The VPN client has a status option but sometimes it doesn't return the correct country, so I wrote a script to check if I'm for instance connected to Sweden. My script looks like this:

#!/bin/bash
 country=Sweden
 service=expressvpn

while true; do
   if ((curl -s http://ift.tt/1N9EnV5  | grep $country | grep -v "grep" | wc -l) > 0 )
   then
      echo "$service connected!!!"
  else
      echo "$service not connected!"
      $service connect $country
 fi;
 sleep 5;
 done

The problem is, it always says "service connected", even when it isn't. When I enter the curl command manually, wc -l returns 0 if it didn't find Sweden and 1 when it does. What's wrong with the if statement? Thank you Peter

Aucun commentaire:

Enregistrer un commentaire