优化日志格式
This commit is contained in:
1 parent
c96234ccbb
commit
e4be654801
1 file changed
+30
-27
@@ -49,8 +49,8 @@ arWanIp4() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$(echo $hostIp | awk '/^[0-9\.]+$/')" ]; then
|
if [ -n "$(echo $hostIp | grep -Ev '^[0-9\.]+$')" ]; then
|
||||||
echo "arWanIp4: No IPv4 address found, please check if you have one"
|
echo "arWanIp4 - Invalid IPv4 address $hostIp"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -75,8 +75,8 @@ arWanIp6() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ -n "$(echo $hostIp | awk '/^[0-9a-zA-Z:]+$/')" ]; then
|
if [ -n "$(echo $hostIp | grep -Ev '^[0-9a-fA-F:]+$')" ]; then
|
||||||
echo "arWanIp6: No IPv6 address found, please check if you have one"
|
echo "arWanIp6 - Invalid IPv6 address"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ arDdnsIds() {
|
|||||||
|
|
||||||
if ! [ "$domainId" -gt 0 ] 2>/dev/null ;then
|
if ! [ "$domainId" -gt 0 ] 2>/dev/null ;then
|
||||||
errMsg=$(echo $domainId | sed 's/.*"message":"\([^\"]*\)".*/\1/')
|
errMsg=$(echo $domainId | sed 's/.*"message":"\([^\"]*\)".*/\1/')
|
||||||
echo "arDdnsIds: $errMsg"
|
echo "arDdnsIds - $errMsg"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ arDdnsIds() {
|
|||||||
|
|
||||||
if ! [ "$recordId" -gt 0 ] 2>/dev/null ;then
|
if ! [ "$recordId" -gt 0 ] 2>/dev/null ;then
|
||||||
errMsg=$(echo $recordId | sed 's/.*"message":"\([^\"]*\)".*/\1/')
|
errMsg=$(echo $recordId | sed 's/.*"message":"\([^\"]*\)".*/\1/')
|
||||||
echo "arDdnsIds: $errMsg"
|
echo "arDdnsIds - $errMsg"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ arDdnsRecordIp() {
|
|||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
errMsg=$(echo $recordIp | sed 's/.*"message":"\([^\"]*\)".*/\1/')
|
errMsg=$(echo $recordIp | sed 's/.*"message":"\([^\"]*\)".*/\1/')
|
||||||
echo "arDdnsRecordIp: $errMsg"
|
echo "arDdnsRecordIp - $errMsg"
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -175,7 +175,7 @@ arDdnsUpdate() {
|
|||||||
local recordCd
|
local recordCd
|
||||||
|
|
||||||
if [ -z "$5" ]; then
|
if [ -z "$5" ]; then
|
||||||
echo "arDdnsUpdate: Args number error"
|
echo "arDdnsUpdate - Args number error"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -186,11 +186,11 @@ arDdnsUpdate() {
|
|||||||
|
|
||||||
# Output Result
|
# Output Result
|
||||||
if [ "$recordIp" = "$4" ] && [ "$recordCd" = "1" ]; then
|
if [ "$recordIp" = "$4" ] && [ "$recordCd" = "1" ]; then
|
||||||
echo "arDdnsUpdate: success"
|
echo "arDdnsUpdate - success"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
errMsg=$(echo $recordRs | sed 's/.*,"message":"\([^"]*\)".*/\1/')
|
errMsg=$(echo $recordRs | sed 's/.*,"message":"\([^"]*\)".*/\1/')
|
||||||
echo "arDdnsUpdate: $errMsg"
|
echo "arDdnsUpdate - $errMsg"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -200,6 +200,8 @@ arDdnsUpdate() {
|
|||||||
# Args: Main Sub
|
# Args: Main Sub
|
||||||
arDdnsCheck() {
|
arDdnsCheck() {
|
||||||
|
|
||||||
|
local errCode
|
||||||
|
|
||||||
local recordType
|
local recordType
|
||||||
local hostIp
|
local hostIp
|
||||||
|
|
||||||
@@ -207,6 +209,7 @@ arDdnsCheck() {
|
|||||||
local lastIp
|
local lastIp
|
||||||
local postRs
|
local postRs
|
||||||
|
|
||||||
|
echo "Fetching Host Ip"
|
||||||
if [ "$3" = "6" ]; then
|
if [ "$3" = "6" ]; then
|
||||||
recordType=AAAA
|
recordType=AAAA
|
||||||
hostIp=$(arWanIp6)
|
hostIp=$(arWanIp6)
|
||||||
@@ -215,39 +218,39 @@ arDdnsCheck() {
|
|||||||
hostIp=$(arWanIp4)
|
hostIp=$(arWanIp4)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
errCode=$?
|
||||||
echo $hostIp
|
echo "> Host Ip: $hostIp"
|
||||||
|
echo "> Record Type: $recordType"
|
||||||
|
if [ $errCode -ne 0 ]; then
|
||||||
return 1
|
return 1
|
||||||
else
|
|
||||||
echo "Record Type: $recordType"
|
|
||||||
echo "Host Ip: $hostIp"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Getting Ids of $2.$1"
|
||||||
ddnsIds=$(arDdnsIds $recordType $1 $2)
|
ddnsIds=$(arDdnsIds $recordType $1 $2)
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
errCode=$?
|
||||||
echo $ddnsIds
|
echo "> Domain Ids: $ddnsIds"
|
||||||
|
if [ $errCode -ne 0 ]; then
|
||||||
return 1
|
return 1
|
||||||
else
|
|
||||||
echo "Domain Ids: $ddnsIds"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Checking Domain: $2.$1"
|
echo "Checking Record for $2.$1"
|
||||||
lastIp=$(arDdnsRecordIp $ddnsIds)
|
lastIp=$(arDdnsRecordIp $ddnsIds)
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
errCode=$?
|
||||||
echo $lastIp
|
echo "> Last Ip: $lastIp"
|
||||||
|
if [ $errCode -ne 0 ]; then
|
||||||
return 1
|
return 1
|
||||||
else
|
|
||||||
echo "Last Ip: $lastIp"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$lastIp" == "$hostIp" ]; then
|
if [ "$lastIp" == "$hostIp" ]; then
|
||||||
echo "Last Ip is the same as host Ip"
|
echo "> Last Ip is the same as host Ip"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Updating Domain: $2.$1"
|
echo "Updating Record for $2.$1"
|
||||||
arDdnsUpdate $ddnsIds $2 $hostIp $recordType
|
postRs=$(arDdnsUpdate $ddnsIds $2 $hostIp $recordType)
|
||||||
|
|
||||||
|
echo "> $postRs"
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user