Removed seperate crontab script

This commit is contained in:
Anon 2022-09-29 00:14:03 -07:00
parent 706d7c8c4e
commit 9b502d6196
3 changed files with 10 additions and 45 deletions

View File

@ -60,7 +60,7 @@ Next you need to login to your Cloudflare account and generate the API tokens fo
- Run `./run.sh` to change it back. It should auto detect your web-facing IP and update the A record accordingly. - Run `./run.sh` to change it back. It should auto detect your web-facing IP and update the A record accordingly.
## Automate DynamicCloudflareDNS ## Automate DynamicCloudflareDNS
There are a myriad of ways to automate calling a script at regular intervals on Linux. For brevity I will be covering the cron way. There are a several ways to automate calling a script at regular intervals on Linux. For brevity I will be covering the cron way.
First off, install cron if it's not already installed: First off, install cron if it's not already installed:
``` ```
@ -70,15 +70,11 @@ sudo systemctl enable cronie
sudo systemctl start cronie sudo systemctl start cronie
``` ```
Next, instead of calling run.sh with cron, we will be calling cron.sh. This is basically a wrapper script that will call run.sh, and pipe the output to `$HOME/cron/DynamicCloudflareDNS.log` so we can keep track of IP changes, as well as any errors that are generated. Next, run the following commands:
- `EDITOR=nvim crontab -e`
To do this follow the instructions below: - `*/2 * * * * /absolute/path/to/run.sh >> "${HOME}/cron/DynamicCloudflareDNS.log" 2>&1`
- Make any changes you want to the log path in cron.sh - Modify the paths above to suit your preferances
- Run `./cron.sh` and make sure that it generated normal output to the log path (nothing should appear in the terminal window) - Save and exit
- If everything worked, run the following commands replacing nvim with your editor of choice:
- `EDITOR=nvim crontab -e`
- `*/2 * * * * /absolute/path/to/cron.sh`
- Save and exit
If you followed the steps above the cron job should run every two minutes. Tail the log file to ensure it's working correctly. If you followed the steps above the cron job should run every two minutes. Tail the log file to ensure it's working correctly.

35
cron.sh
View File

@ -1,35 +0,0 @@
#! /usr/bin/env bash
# Dynamic Cloudflare DNS, a way to automate DNS changes for Cloudflare
# Copyright (C) 2022 Anon
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Add the following to your crontab
# EDITOR=nvim crontab -e
# */2 * * * * DynamicCloudflareDNS
# Get the runtime path of the bot
ABS_PATH="$(readlink -f "$0")"
RUN_DIR="$(dirname "$ABS_PATH")"
LOGS="${HOME}/cron/DynamicCloudflareDNS.log"
# Relative paths to the virtual environment and main.py
ENTRY='./run.sh'
# cd into the bot's root path, set up the virtual environment, and run
cd "$RUN_DIR"
mkdir -p "$(dirname "$LOGS")"
"$ENTRY" "$@" >> "$LOGS" 2>&1
cd - > /dev/null

4
run.sh
View File

@ -16,6 +16,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# Add the following to your crontab to automate this script
# EDITOR=nvim crontab -e
# */2 * * * * /absolute/path/to/run.sh >> "${HOME}/cron/DynamicCloudflareDNS.log" 2>&1
# Get the runtime path of the bot # Get the runtime path of the bot
ABS_PATH="$(readlink -f "$0")" ABS_PATH="$(readlink -f "$0")"
RUN_DIR="$(dirname "$ABS_PATH")" RUN_DIR="$(dirname "$ABS_PATH")"