现在在用 macbook air m1,太离谱了,一合盖就睡眠断 vpn,然后还有极高概率 dns broken,完全无法自动恢复,经过一段时间摸索,找出来了可行处理手段
合盖不睡眠
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #!/bin/bash
BATTERY_SLEEP=5 DEF_WAKE_LEN=36000
timeout_len=${1:-$DEF_WAKE_LEN}
function prevent_sleep() { echo -n "Preventing sleep for $timeout_len seconds; press <enter> to continue..." sudo pmset -b disablesleep 1 sudo pmset -b sleep 0 }
function enable_sleep() {
if [[ ${1:-1} -eq 1 ]]; then echo; fi
echo "Restoring previous battery sleep setting: $BATTERY_SLEEP" sudo pmset -b disablesleep 0 sudo pmset -b sleep $BATTERY_SLEEP
if [[ ${1:--1} -eq 1 ]]; then sudo pmset sleepnow; fi exit }
prevent_sleep
trap enable_sleep INT
read -t $timeout_len rc=$?
enable_sleep $rc
|
重启系统 dns 服务
1 2 3
|
sudo killall -HUP mDNSResponder
|