From 85b93b8970eb8e20e98583f3021ecc7817278fcb Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Wed, 27 May 2020 10:00:30 -0500 Subject: [PATCH 1/9] Make logging path user adjustable --- backup/BACKUP.md | 3 ++- gravity-sync.sh | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/backup/BACKUP.md b/backup/BACKUP.md index a82e642..d2a627b 100644 --- a/backup/BACKUP.md +++ b/backup/BACKUP.md @@ -1 +1,2 @@ -Your backup files will be stored here. They will be ignored by any git updates. \ No newline at end of file +Your backup files will be stored here. +They will be ignored by any git updates. \ No newline at end of file diff --git a/gravity-sync.sh b/gravity-sync.sh index 59d4631..4a8d321 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -2,7 +2,7 @@ # GRAVITY SYNC BY VMSTAN ##################### PROGRAM='Gravity Sync' -VERSION='1.4.0' +VERSION='1.4.1' # Execute from the home folder of the user who own's it (ex: 'cd ~/gravity-sync') # For documentation or download updates visit https://github.com/vmstan/gravity-sync @@ -15,11 +15,14 @@ VERSION='1.4.0' # GS Folder/File Locations LOCAL_FOLDR='gravity-sync' # must exist in running user home folder -CONFIG_FILE='gravity-sync.conf' # must exist as explained above -SYNCING_LOG='gravity-sync.log' # will be created in above folder -CRONJOB_LOG='gravity-sync.cron' # only used if cron is configured to output to this file +CONFIG_FILE='gravity-sync.conf' # must exist with primary host/user configured BACKUP_FOLD='backup' # must exist as subdirectory in LOCAL_FOLDR +# Logging Folder/File Locations +LOG_PATH="$HOME/${LOCAL_FOLDR}" # replace in gravity-sync.conf to overwrite +SYNCING_LOG='gravity-sync.log' # replace in gravity-sync.conf to overwrite +CRONJOB_LOG='gravity-sync.cron' # replace in gravity-sync.conf to overwrite + # PH Folder/File Locations PIHOLE_DIR='/etc/pihole' # default PH data directory GRAVITY_FI='gravity.db' # default PH database file @@ -249,19 +252,16 @@ function push_gs { ### Write Logs Out function logs_export { echo -e "${INFO} Logging Timestamps to ${SYNCING_LOG}" - # date >> $HOME/${LOCAL_FOLDR}/${SYNCING_LOG} - echo -e $(date) "[${TASKTYPE}]" >> $HOME/${LOCAL_FOLDR}/${SYNCING_LOG} + echo -e $(date) "[${TASKTYPE}]" >> ${LOG_PATH}/${SYNCING_LOG} } ### Output Sync Logs function logs_gs { echo -e "========================================================" echo -e "Recent Complete ${YELLOW}PULL${NC} Executions" - tail -n 10 ${SYNCING_LOG} | grep PULL - #echo -e "Recent Complete ${YELLOW}UPDATE${NC} Executions" - # tail -n 10 ${SYNCING_LOG} | grep UPDATE + tail -n 10 ${LOG_PATH}/${SYNCING_LOG} | grep PULL echo -e "Recent Complete ${YELLOW}PUSH${NC} Executions" - tail -n 10 ${SYNCING_LOG} | grep PUSH + tail -n 10 ${LOG_PATH}/${SYNCING_LOG} | grep PUSH echo -e "========================================================" exit_nochange } @@ -269,25 +269,25 @@ function logs_gs { ## Crontab Logs ### Core Crontab Logs function show_crontab { - CRONPATH="$HOME/${LOCAL_FOLDR}/${CRONJOB_LOG}" + import_gs MESSAGE="Replaying Last Cronjob" echo -en "${STAT} ${MESSAGE}" - if [ -f ${CRONPATH} ] + if [ -f ${LOG_PATH}/${CRONJOB_LOG} ] then - if [ -s ${CRONPATH} ] + if [ -s ${LOG_PATH}/${CRONJOB_LOG} ] echo -e "\r${GOOD} ${MESSAGE}" logs_crontab exit_nochange then echo -e "\r${FAIL} ${MESSAGE}" - echo -e "${INFO} ${CRONPATH} appears empty" + echo -e "${INFO} ${LOG_PATH}/${CRONJOB_LOG} appears empty" exit_nochange fi else echo -e "\r${FAIL} ${MESSAGE}" - echo -e "${INFO} ${CRONPATH} cannot be located" + echo -e "${INFO} ${LOG_PATH}/${CRONJOB_LOG} cannot be located" exit_nochange fi } @@ -297,7 +297,7 @@ function logs_crontab { echo -e "========================================================" echo -e "========================================================" echo -e "" - cat ${CRONJOB_LOG} + cat ${LOG_PATH}/${CRONJOB_LOG} echo -e "" echo -e "========================================================" echo -e "========================================================" From 7afa6fd461af6df50c3bcaf8b8116c9273cc2fb0 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Wed, 27 May 2020 10:18:58 -0500 Subject: [PATCH 2/9] Cleanup cron output --- gravity-sync.sh | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 4a8d321..6d47347 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -278,7 +278,11 @@ function show_crontab { then if [ -s ${LOG_PATH}/${CRONJOB_LOG} ] echo -e "\r${GOOD} ${MESSAGE}" - logs_crontab + + echo -e "========================================================" + echo -e date -r ${LOG_PATH}/${CRONJOB_LOG} + cat ${LOG_PATH}/${CRONJOB_LOG} + echo -e "========================================================" exit_nochange then echo -e "\r${FAIL} ${MESSAGE}" @@ -292,17 +296,6 @@ function show_crontab { fi } -### Output Crontab -function logs_crontab { - echo -e "========================================================" - echo -e "========================================================" - echo -e "" - cat ${LOG_PATH}/${CRONJOB_LOG} - echo -e "" - echo -e "========================================================" - echo -e "========================================================" -} - # Validate Functions ## Validate GS Folders function validate_gs_folders { From 7b59fafda8e08d463af34da5a64688517ef169a5 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Wed, 27 May 2020 10:20:14 -0500 Subject: [PATCH 3/9] Update gravity-sync.sh --- gravity-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 6d47347..27498ff 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -280,7 +280,7 @@ function show_crontab { echo -e "\r${GOOD} ${MESSAGE}" echo -e "========================================================" - echo -e date -r ${LOG_PATH}/${CRONJOB_LOG} + date -r ${LOG_PATH}/${CRONJOB_LOG} cat ${LOG_PATH}/${CRONJOB_LOG} echo -e "========================================================" exit_nochange From f38ca58902cd8b5fc1b8e448e707d2a0e0df0216 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Wed, 27 May 2020 10:50:09 -0500 Subject: [PATCH 4/9] First commit with VSCode --- gravity-sync.conf.example | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gravity-sync.conf.example b/gravity-sync.conf.example index b949bf9..62c679e 100644 --- a/gravity-sync.conf.example +++ b/gravity-sync.conf.example @@ -6,7 +6,7 @@ REMOTE_HOST='192.168.1.10' # User account on primary with SUDO rights REMOTE_USER='pi' -# OPTIONAL SETTING ####################### +# OPTIONAL SETTINGS ###################### # Password for REMOTE_USER account # Requires 'SSHPASS' installed on server @@ -14,4 +14,15 @@ REMOTE_USER='pi' # Less secure and possibly less reliable # Leave blank to use (preferred) key-pair -REMOTE_PASS='' \ No newline at end of file +REMOTE_PASS='' + +# ADVANCED SETTINGS ###################### + +# Uncomment and set for auxillary control +# Overrides gravity-sync.sh defaults + +# SSH_PORT='' +# SSH_PKIF='' +# LOG_PATH='' +# SYNCING_LOG='' +# CRONJOB_LOG='' \ No newline at end of file From 6f39abc44d314219d7cb5f3ff21a98030f144084 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Wed, 27 May 2020 11:04:22 -0500 Subject: [PATCH 5/9] Log path oddity --- gravity-sync.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 27498ff..97aaa8c 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -259,9 +259,9 @@ function logs_export { function logs_gs { echo -e "========================================================" echo -e "Recent Complete ${YELLOW}PULL${NC} Executions" - tail -n 10 ${LOG_PATH}/${SYNCING_LOG} | grep PULL + tail -n 7 ${LOG_PATH}/${SYNCING_LOG} | grep PULL echo -e "Recent Complete ${YELLOW}PUSH${NC} Executions" - tail -n 10 ${LOG_PATH}/${SYNCING_LOG} | grep PUSH + tail -n 7 ${LOG_PATH}/${SYNCING_LOG} | grep PUSH echo -e "========================================================" exit_nochange } From 77ee1839bbc23018a003f038a1a50a0eb655f41a Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Wed, 27 May 2020 11:06:35 -0500 Subject: [PATCH 6/9] Quotes? --- gravity-sync.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 97aaa8c..4e4e469 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -259,9 +259,9 @@ function logs_export { function logs_gs { echo -e "========================================================" echo -e "Recent Complete ${YELLOW}PULL${NC} Executions" - tail -n 7 ${LOG_PATH}/${SYNCING_LOG} | grep PULL + tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PULL echo -e "Recent Complete ${YELLOW}PUSH${NC} Executions" - tail -n 7 ${LOG_PATH}/${SYNCING_LOG} | grep PUSH + tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PUSH echo -e "========================================================" exit_nochange } From c5752b335c798d790aecc9d1f7b32d2dc1b11a4b Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Wed, 27 May 2020 11:09:07 -0500 Subject: [PATCH 7/9] Import custom settings for logging --- gravity-sync.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gravity-sync.sh b/gravity-sync.sh index 4e4e469..6ed3227 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -257,6 +257,8 @@ function logs_export { ### Output Sync Logs function logs_gs { + import_gs + echo -e "========================================================" echo -e "Recent Complete ${YELLOW}PULL${NC} Executions" tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PULL From 4a80caece1485558f4432db541cfcc3d6a2d8b3a Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Wed, 27 May 2020 11:13:04 -0500 Subject: [PATCH 8/9] Add info to show log location --- gravity-sync.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 6ed3227..1c23e51 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -258,7 +258,8 @@ function logs_export { ### Output Sync Logs function logs_gs { import_gs - + + echo -e "${INFO} Tailing ${LOG_PATH}/${SYNCING_LOG}" echo -e "========================================================" echo -e "Recent Complete ${YELLOW}PULL${NC} Executions" tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PULL From d1d86c51a5a930b0fdae060526790d56290cd2a7 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Wed, 27 May 2020 11:20:29 -0500 Subject: [PATCH 9/9] Add tail line to cronjob --- gravity-sync.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/gravity-sync.sh b/gravity-sync.sh index 1c23e51..05d34b0 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -282,6 +282,7 @@ function show_crontab { if [ -s ${LOG_PATH}/${CRONJOB_LOG} ] echo -e "\r${GOOD} ${MESSAGE}" + echo -e "${INFO} Tailing ${LOG_PATH}/${CRONJOB_LOG}" echo -e "========================================================" date -r ${LOG_PATH}/${CRONJOB_LOG} cat ${LOG_PATH}/${CRONJOB_LOG}