Its been about 9 months in Vietnam now. One problem that I have to deal with on a day to day basis here is the flaky Internet connection. There are good days and bad days and bad days are incredibly frustrating. The Internet is ON and OFF every five minutes. I wrote this simple script which will wait for the Internet to be active before executing commands given to the script as an argument. I have found this very useful for commands like git pull/push, svn update etc.

PING=$(ping -q -c 1 &>/dev/null; echo $?)
while [ $PING -gt 0 ]; do
  PING=$(ping -q -c 1 &>/dev/null; echo $?)

I call it "wfi", wait-for-internet. Dump this script into your bin directory and give it executable permissions.

To test this script, disconnect your wifi/ethernet connection and then run the following command.

wfi ls -l

Reconnect your wifi/ethernet, and you'll see that the command gets executed as soon as your Internet connection is up.

wfi git pull

Now I can execute these commands through wfi and then go back to my work and be less exasperated.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You May Also Like

Error While Parsing Json using Python – TypeError: list indices must be integers, not str

Jotting this down for fellow googlers. I recently started learning a bit…

Makefile Tricks: Arithmetic – Addition, Subtraction, Multiplication, Division, Modulo, Comparison

While working on a project, I needed to do some calculations inside…