1
0
mirror of https://github.com/namibia/demo-sync.git synced 2024-11-24 20:27:33 +00:00

Added dynamic cron timer option.

This commit is contained in:
Llewellyn van der Merwe 2020-03-06 17:19:08 +02:00
parent 075f2d5bd3
commit efa5b42f05
No known key found for this signature in database
GPG Key ID: 8A8F406BA7238C4E
2 changed files with 9 additions and 5 deletions

View File

@ -8,5 +8,5 @@ bash <(curl -s https://raw.githubusercontent.com/namibia/demo-sync/master/sync.s
``` ```
This script performs the following actions: This script performs the following actions:
* Adds a cron entry to update run this sync on a scheduled basis. * Adds a cron entry to run this sync on a scheduled basis.
* Adds folder and database setup file to use in scheduled syncs * Adds folders and databases data to use in scheduled syncs.

10
sync.sh
View File

@ -125,7 +125,7 @@ function setCron () {
echoTweak "Crontab already configured for updates..." echoTweak "Crontab already configured for updates..."
echo "Skipping" echo "Skipping"
else else
echoTweak "Adding crontab entry for continued updates..." echo "Adding crontab entry for continued updates..."
# check if user crontab is set # check if user crontab is set
currentCron=$(crontab -u $CLIENTUSER -l 2>/dev/null) currentCron=$(crontab -u $CLIENTUSER -l 2>/dev/null)
if [[ -z "${currentCron// }" ]]; then if [[ -z "${currentCron// }" ]]; then
@ -139,9 +139,13 @@ function setCron () {
echo "MAILTO=\"\"" >> "${CRONPATH}" echo "MAILTO=\"\"" >> "${CRONPATH}"
echo "" >> "${CRONPATH}" echo "" >> "${CRONPATH}"
fi fi
# get the Source Database IP/Domain
echo -ne "\n Add the cron timer here so you sync will run every day at 4am.\n"
echo -ne " # That will look like our example below, see https://crontab.guru/#0_4_*_*_* for more details.\n"
read -e -p " # Example (0 4 * * *): " -i "0 4 * * *" INPUT_CRON_CICLE
# check if the @reboot curl -s $SCRIPTURL | sudo bash is already set # check if the @reboot curl -s $SCRIPTURL | sudo bash is already set
if [[ $currentCron != *"0 4 * * * curl -s $SCRIPTURL | bash"* ]]; then if [[ $currentCron != *"${INPUT_CRON_CICLE} curl -s $SCRIPTURL | bash"* ]]; then
echo "0 4 * * * curl -s $SCRIPTURL | bash" >> "${CRONPATH}" echo "${INPUT_CRON_CICLE} curl -s $SCRIPTURL | bash" >> "${CRONPATH}"
fi fi
# set the user cron # set the user cron
crontab -u $ACTIVEUSER "${CRONPATH}" crontab -u $ACTIVEUSER "${CRONPATH}"