Wait for network

Submitted by code_admin on Wed, 07/25/2018 - 15:51

Bash script that will wait for a network connection

  1. #!/bin/bash
  2.  
  3. PINGDEST=8.8.8.8
  4.  
  5. echo "Waiting for ping response from ${PINGDEST}"
  6.  
  7. COUN=1
  8. while true; do
  9.   printf "."
  10.   ping -c1 ${PINGDEST} > /dev/null && break;
  11.   sleep 1
  12.   COUN=${COUN}+1
  13.   if [[ ${COUN} -gt 10 ]]; then
  14.     printf "\n"
  15.     echo "ERROR timed out wiating for ${PINGDEST}"
  16.     exit 1
  17.   fi
  18. done
  19. printf "\n"
  20. echo "Ping recieved"
  21. exit 0

Tags

RJM Article Type
Quick Reference