Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Code Block
titleautochangedns.sh
#!/bin/bash
export SecretId=your SecretId
export SecretKey=your SecretKey
domain_name=$1
record_name=$2
webhookurl=https://oapi.dingtalk.com/robot/send?access_token=0ccbf717fb61bef56d0cc29d25b5d7e79da719997c5d0dca55f709bd54e5ef32your dingdingtoken
time=$(date)
#currentdnsip=$(dig +short $record_name.$domain_name A)
currentrecordip=$(python3 /shell/listdns.py $domain_name $record_name)
currentserverip=$(timeout 5 curl -s ifconfig.me)
message="{
    \"msgtype\": \"markdown\",
    \"markdown\": {
        \"title\": \"DNS记录修改\",
        \"text\": \"#### DNS记录修改\n\n- 时间: **$time**\n- 域名: **${record_name}.${domain_name}**\n- IP:**$currentserverip**\n\"
    }
}"

if [ "$currentrecordip" = "$currentserverip" ]; then
    echo "The current DNS IP and server IP are the same: $currentrecordip"
    exit 0
else
    echo "The current DNS IP ($currentrecordip) does not match the server IP ($currentserverip). Updating DNS..."
    python3 /shell/changedns.py $domain_name $record_name $currentserverip
    curl -s "${webhookurl}" -H 'Content-Type: application/json' -d "${message}"
fi

...