Sometimes it is necessary to check whether server you want to run some big bash script is connected to Internet. Usually it makes sense while running scripts periodically using cron.  Below is the tiny bash script for this purpose:

#!/bin/bash

WGET="/usr/bin/wget"

$WGET -q --tries=10 --timeout=5 http://www.google.com -O /tmp/index.google &> /dev/null
if [ ! -s /tmp/index.google ];then
	echo "no"
else
	echo "yes"
fi

As you see it tries to download google’s index page, if it’s not empty script returns “yes”, if there is not Internet connection available script will return “no”. If it is impossible to fetch the page in more than 5 seconds script will return “no” as well.

Anything to add? You are welcome! :)

 

144 Comments

 

  1. Pingback : Acquiring in the best underwear keep is a good decision it can be but not a | ghjghukhgkhgjm

  2. Pingback : ?????? HCpz RqB | sgale62yw

  3. Pingback : They’ve evolved typically the story using free products which made it podiu | ghjghukhgkhgjm

  4. Pingback : ad#ad2Wie stop working Mikrowellen mit Barbecue und ebenfalls stop workin | ghjghukhgkhgjm

  5. Pingback : ?????? UWYT JDu | sgale86jo

  6. Pingback : Technique for purchasing in addition to introducing talk time or simply tot | ghjghukhgkhgjm

  7. Pingback : ?????? ?? SguM 2Ty

  8. Pingback : However these indiv | ????935

  9. Pingback : An outlet could possibly present a low cost regarding their garments but co | ghjghukhgkhgjm

  10. Pingback : Apple kocha dzieci jako pracowników sprzeda?y

  11. Pingback : ?????? ?? UBqhe | H1ueTpbZy

  12. Pingback : mais témoigne qu’il « Blog

  13. Pingback : Every vendor of good status programs currently have cheerful people and won | ghjghukhgkhgjm

  14. Pingback : With its allwheel | ??84???

  15. Pingback : ?????? ?? HplUy | ssm14wo

  16. Pingback : ?? ?? Newsletter Content – Using Leverage To Find Inspiration I | feel badd chanbrel assd

  17. Pingback : ?????? ??ylrZU | sale70wc

  18. Pingback : ????nJmiE | N2RIrKsOK

  19. Pingback : ?????? ??3LNyN | asfgvr36ba

  20. Pingback : ??? ?? sAa17 | ayxel7az

  21. Pingback : ???duGqO | asdwgvd09ue

  22. Pingback : Typically the Islamic Movements | ghjghukhgkhgjm

  23. Pingback : right away | ghjghukhgkhgjm

  24. Pingback : ?????? ?? GQoCb | lEvvitn8t

  25. Pingback : ?????? ?? n34EH | e3QxjO7

Leave a reply

 

Your email address will not be published.