Skip to content

Commit

Permalink
Create cron job automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
navilg committed Jul 8, 2020
1 parent cfbc533 commit 52eb7b0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions godaddyDDNS.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,42 @@ function setDNSRecord()
echo "DNS Name: "$name.$domain"" > $DIR/godaddyDDNS.log
echo "DNS IP: $currentIp" >> $DIR/godaddyDDNS.log
echo "Status: OK" >> $DIR/godaddyDDNS.log
return 0
else
# If any error
echo "DNS Name: "$name.$domain"" > $DIR/godaddyDDNS.log
echo "DNS IP: $currentIp" >> $DIR/godaddyDDNS.log
echo "Status: NOT OK - $result" >> $DIR/godaddyDDNS.log
return 1
fi
else
# Ips and ttl are equal
echo "DNS Name: "$name.$domain"" > $DIR/godaddyDDNS.log
echo "DNS IP: $currentIp" >> $DIR/godaddyDDNS.log
echo "Status: OK" >> $DIR/godaddyDDNS.log
return 0
fi
}

function addCronJobs()
{
crontab -l > $DIR/godaddyDDNS.cron
grep -v "^#" $DIR/godaddyDDNS.cron | grep -i "$DIR/godaddyDDNS.sh"
croncheck=$?
if [[ $croncheck -ne 0 ]]; then
echo "*/5 * * * * $DIR/godaddyDDNS.sh >/dev/null 2>&1" >> $DIR/godaddyDDNS.cron
echo "@reboot $DIR/godaddyDDNS.sh >/dev/null 2>&1" >> $DIR/godaddyDDNS.cron
crontab "$DIR/godaddyDDNS.cron"
fi
rm -f $DIR/godaddyDDNS.cron
}

# Main - Function call
initialize
getDNSRecord
getPubIP
setDNSRecord
checkstatus=$?
if [[ $checkstatus -eq 0 ]]; then
addCronJobs
fi

0 comments on commit 52eb7b0

Please sign in to comment.