From 662985dc3bd06e83486708fc4004468ffbbc0fbe Mon Sep 17 00:00:00 2001 From: Nicholas Drone Date: Mon, 19 Jul 2021 16:26:13 -0400 Subject: [PATCH] Updates Logging Instead of creating a log file. This change leverages the syslog. This allows us to not have to manually rotate logs, or worry about the log file filling up the file system. This also give us timestamps of the logging without having to create the timestamps ourselves. Messages are logged to /var/log/messages by default. --- cloudflare-template.sh | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/cloudflare-template.sh b/cloudflare-template.sh index ca0f79b..c430391 100644 --- a/cloudflare-template.sh +++ b/cloudflare-template.sh @@ -9,22 +9,13 @@ proxy=false # Set the proxy to true or fa -########################################### -## Define date time stamp function -########################################### -function ds() { - date +"[%F %T]" -} - - ########################################### ## Check if we have a public IP ########################################### ip=$(curl -s https://api.ipify.org || curl -s https://ipv4.icanhazip.com/) if [ "${ip}" == "" ]; then - message="$(ds) No public IP found." - >&2 echo -e "${message}" >> ~/log + logger "DDNS Updater: No public IP found" exit 1 fi @@ -41,15 +32,14 @@ fi ## Seek for the A record ########################################### -echo "$(ds) Check Initiated" >> ~/log +logger "DDNS Updater: Check Initiated" record=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records?name=$record_name" -H "X-Auth-Email: $auth_email" -H "$auth_header $auth_key" -H "Content-Type: application/json") ########################################### ## Check if the domain has an A record ########################################### if [[ $record == *"\"count\":0"* ]]; then - message="$(ds) Record does not exist, perhaps create one first? (${ip} for ${record_name})" - >&2 echo -e "${message}" >> ~/log + logger "DDNS Updater: Record does not exist, perhaps create one first? (${ip} for ${record_name})" exit 1 fi @@ -59,8 +49,7 @@ fi old_ip=$(echo "$record" | grep -Po '(?<="content":")[^"]*' | head -1) # Compare if they're the same if [[ $ip == $old_ip ]]; then - message="$(ds) IP ($ip) for ${record_name} has not changed." - echo "${message}" >> ~/log + logger "DDNS Updater: IP ($ip) for ${record_name} has not changed." exit 0 fi @@ -83,11 +72,9 @@ update=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identi ########################################### case "$update" in *"\"success\":false"*) - message="$(ds) $ip $record_name DDNS failed for $record_identifier ($ip). DUMPING RESULTS:\n$update" - >&2 echo -e "${message}" >> ~/log + logger "DDNS Updater: $ip $record_name DDNS failed for $record_identifier ($ip). DUMPING RESULTS:\n$update" exit 1;; *) - message="$(ds) $ip $record_name DDNS updated." - echo "${message}" >> ~/log + logger "DDNS Updater: $ip $record_name DDNS updated." exit 0;; esac