Last active
October 24, 2020 11:22
-
-
Save asid21/a70e69d5e484487a0a24603a1bdbf85e to your computer and use it in GitHub Desktop.
Wi-Fiの調子が悪い時に自動的に再接続をするためのシェルスクリプト(Mac用)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| while true | |
| do | |
| # タイムアウト(1秒)を設定してcurl | |
| curl -m 1 google.com >/dev/null 2>&1 | |
| # curlに失敗 | |
| if [ $? -ne 0 ] | |
| then | |
| # Wi-Fiの再接続 | |
| echo -n "![" | |
| networksetup -setairportpower en0 off | |
| sleep 5 | |
| networksetup -setairportpower en0 on | |
| # 何かのSSIDに接続できるまで待つ | |
| while true | |
| do | |
| sleep 1 | |
| if airport -I | grep "state: *running" >/dev/null 2>&1 | |
| then | |
| sleep 1 | |
| break | |
| fi | |
| done | |
| echo -n "]" | |
| else | |
| echo -n "." | |
| sleep 1 | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment