From c289e71548587c0bf82d7a012c97aa7e647eaf37 Mon Sep 17 00:00:00 2001 From: deajan Date: Sun, 26 Apr 2015 22:32:43 +0200 Subject: [PATCH] Improved osync-batch.sh for crontab execution --- CHANGELOG.md | 1 + osync-batch.sh | 34 ++++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45629c3..137fc71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ UNDER WORK RECENT CHANGES -------------- +- Added detection of osync.sh script in osync-batch.sh to overcome mising path in crontab - Fixed osync-batch.sh script when osync is in executable path like /usr/local/bin - Fixed multiple keep logging messages since sleep time between commands has been lowered under a second - Added optional checksum parameter for the paranoid :) diff --git a/osync-batch.sh b/osync-batch.sh index 7bcb7b1..0aa31c8 100755 --- a/osync-batch.sh +++ b/osync-batch.sh @@ -3,7 +3,7 @@ PROGRAM="Osync-batch" # Batch program to run osync instances sequentially and rerun failed ones AUTHOR="(L) 2013-2014 by Orsiris \"Ozy\" de Jong" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" -PROGRAM_BUILD=2404201501 +PROGRAM_BUILD=2504201501 ## Runs an osync instance for every conf file found ## If an instance fails, run it again if time permits @@ -17,15 +17,6 @@ MAX_EXECUTION_TIME=36000 ## Specifies the number of reruns an instance may get MAX_RERUNS=3 - -## Osync executable full path can be set here if it cannot be found on the system -if ! type -p osync.sh > /dev/null 2>&1 -then - OSYNC_EXECUTABLE=./osync.sh -else - OSYNC_EXECUTABLE=$(type -p osync.sh) -fi - ## Log file path if [ -w /var/log ] then @@ -47,6 +38,25 @@ function Log fi } +function CheckEnvironment +{ + ## Osync executable full path can be set here if it cannot be found on the system + if ! type -p osync.sh > /dev/null 2>&1 + then + if [ -f /usr/local/bin/osync.sh ] + then + OSYNC_EXECUTABLE=/usr/local/bin/osync.sh + elif [ -f ./osync.sh ] + then + OSYNC_EXECUTABLE=./osync.sh + else + Log "Could not find osync.sh" + exit 1 + fi + else + OSYNC_EXECUTABLE=$(type -p osync.sh) + fi +} function Batch { @@ -77,8 +87,7 @@ function Batch else RUN_AGAIN=$RUN_AGAIN" $i" fi - elif [ $verbose -eq 1 ] - then + else Log "Run instance $(basename $i) succeed." fi done @@ -145,5 +154,6 @@ do esac done +CheckEnvironment Log "$(date) Osync batch run" Batch