2021-12-24 14:01:28 +00:00
|
|
|
#Aparentemente tem um momento em que quando o dns não está funcionando o dig também não retorna nada, então para o script a conexão está funcionando
|
|
|
|
source /home/bruno/enableDongleWifi.sh
|
|
|
|
|
2019-06-14 05:35:57 +00:00
|
|
|
function isDNSWorking() {
|
2021-12-24 14:01:28 +00:00
|
|
|
return $(dig brunofontes.net | grep "ANSWER: 0")
|
2019-06-14 05:35:57 +00:00
|
|
|
}
|
|
|
|
logfile="/var/log/bfontes"
|
|
|
|
|
2021-12-24 14:01:28 +00:00
|
|
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Checking if DNS is working" | sudo tee -a "$logfile"
|
|
|
|
dnsWorking=`isDNSWorking`
|
|
|
|
echo "$dnsWorking"
|
2019-06-14 05:35:57 +00:00
|
|
|
|
|
|
|
if [ "$dnsWorking" ]; then
|
2021-12-24 14:01:28 +00:00
|
|
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - DNS not working, hour may be wrong. Trying to fix..." | sudo tee -a "$logfile"
|
2019-06-14 05:35:57 +00:00
|
|
|
sudo chattr -i /etc/resolv.conf
|
|
|
|
sudo sed -i 's/127.0.0.2/9.9.9.9/' /etc/resolv.conf 2>>"$logfile"
|
|
|
|
sudo chattr +i /etc/resolv.conf
|
|
|
|
|
2021-12-24 14:01:28 +00:00
|
|
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Forcing time to sync" | sudo tee -a "$logfile"
|
2019-06-14 05:35:57 +00:00
|
|
|
sudo chronyc online 2>"$logfile"
|
|
|
|
sudo chronyc -a 'burst 4/4'
|
|
|
|
i=0
|
|
|
|
while [ "$dnsWorking" -a $i -le 4 ]; do
|
2021-12-24 14:01:28 +00:00
|
|
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Waiting..." | sudo tee -a "$logfile"
|
2019-06-14 05:35:57 +00:00
|
|
|
sleep 20
|
2021-12-24 14:01:28 +00:00
|
|
|
dnsWorking=`isDNSWorking`
|
2019-06-14 05:35:57 +00:00
|
|
|
i=$(( "$i" + 1 ))
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "$dnsWorking" ]; then
|
2021-12-24 14:01:28 +00:00
|
|
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - FIXED!" | sudo tee -a "$logfile"
|
2019-06-14 05:35:57 +00:00
|
|
|
else
|
2021-12-24 14:01:28 +00:00
|
|
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Script has failed..." | sudo tee -a "$logfile"
|
|
|
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Fixing DNS script has failed. More details on $logfile" | sudo tee -a ~/.log_error
|
2019-06-14 05:35:57 +00:00
|
|
|
fi
|
2021-12-24 14:01:28 +00:00
|
|
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Configuring DNS servers back." | sudo tee -a "$logfile"
|
2019-06-14 05:35:57 +00:00
|
|
|
sudo chattr -i /etc/resolv.conf
|
|
|
|
sudo sed -i 's/9.9.9.9/127.0.0.2/' /etc/resolv.conf
|
|
|
|
sudo chattr +i /etc/resolv.conf
|
|
|
|
fi
|
2021-12-24 14:01:28 +00:00
|
|
|
sudo echo "$(date +"%Y-%m-%d %H:%M:%S") - Done" | sudo tee -a "$logfile"
|