How to test an Internet connection with bash?

后端 未结 19 1266
青春惊慌失措
青春惊慌失措 2020-11-27 09:26

How can an internet connection be tested without pinging some website? I mean, what if there is a connection but the site is down? Is there a check for a connection with the

相关标签:
19条回答
  • 2020-11-27 10:28

    This bash script continuously check for Internet and make a beep sound when the Internet is available.

    #!/bin/bash
    play -n synth 0.3 sine 800 vol 0.75
    while :
    do
    pingtime=$(ping -w 1 8.8.8.8 | grep ttl)
    if [ "$pingtime" = "" ] 
    then 
       pingtimetwo=$(ping -w 1 www.google.com | grep ttl) 
       if [ "$pingtimetwo" = "" ] 
       then 
           clear ; echo 'Offline'
       else
           clear ; echo 'Online' ; play -n synth 0.3 sine 800 vol 0.75
       fi 
    else
        clear ; echo 'Online' ; play -n synth 0.3 sine 800 vol 0.75
    fi
    sleep 1
    done
    
    0 讨论(0)
提交回复
热议问题