How to check internet access using bash script in linux?

前端 未结 10 1398
孤街浪徒
孤街浪徒 2021-02-01 06:43

In my school, the internet is not available(every night after 23:0 the school will kill the internet, to put us in bed >..<), then the ping will never stop, though I have use

10条回答
  •  感动是毒
    2021-02-01 07:27

    Using the example above, I wrote this script to log the state of your connection: https://gist.github.com/cganterh/ffc2fffa8263857cbece

    First, save the following code into a name.sh file.

    #!/bin/bash
    
    while true
    do
        wget -q --tries=10 --timeout=20 -O - http://google.com > /dev/null
        if [[ $? -eq 0 ]]; then
            echo $(date) "1" | tee -a log.csv
        else
            echo $(date) "0" | tee -a log.csv
        fi
        sleep 5
    done
    

    Then, execute name.sh file in terminal, then check the log state information in log.csv of the same folder.

提交回复
热议问题