Coding style compliance continues

pull/36/head
deajan 9 years ago
parent a2c9d4860b
commit b9bfbb3974

@ -64,3 +64,11 @@ The eval command should always contain 2>1&.
There's a special case where this is needed:
eval "some;commands" 2>> "$LOG_FILE" in order to get error messages into the log.
7. Version numbering
Using bind style versionning:
YYYYMMDDVV (Year, Month, Day, Revision)
Ex:
2015012402 = 2nd revision of 24 Jan 2015

@ -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=2015082501
PROGRAM_BUILD=2015090801
## Runs an osync instance for every conf file found
## If an instance fails, run it again if time permits
@ -26,13 +26,43 @@ fi
# No need to edit under this line ##############################################################
function Log {
function _logger {
local value="${1}" # What to log
echo -e "$value" >> "$LOG_FILE"
if [ $silent -eq 0 ]; then
echo -e "$value"
fi
}
function Logger {
local value="${1}" # What to log
local level="${2}" # Log level: DEBUG, NOTICE, WARN, ERROR, CRITIAL
# Special case in daemon mode we should timestamp instead of counting seconds
if [ $sync_on_changes -eq 1 ]; then
prefix="$(date) - "
else
prefix="TIME: $SECONDS - "
echo -e "$prefix$1" >> "$LOG_FILE"
fi
if [ $silent -eq 0 ]
then
echo -e "$prefix$1"
if [ "$level" == "CRITICAL" ]; then
_logger "$prefix\e[41m$value\e[0m"
ERROR_ALERT=1
elif [ "$level" == "ERROR" ]; then
_logger "$prefix\e[91m$value\e[0m"
ERROR_ALERT=1
elif [ "$level" == "WARN" ]; then
_logger "$prefix\e[93m$value\e[0m"
elif [ "$level" == "NOTICE" ]; then
_logger "$prefix$value"
elif [ "$level" == "DEBUG" ]; then
if [ "$DEBUG" == "yes" ]; then
_logger "$prefix$value"
fi
else
_logger "\e[41mLogger function called without proper loglevel.\e[0m"
_logger "$prefix$value"
fi
}
@ -47,7 +77,7 @@ function CheckEnvironment {
then
OSYNC_EXECUTABLE=./osync.sh
else
Log "Could not find osync.sh"
Logger "Could not find osync.sh" "CRITICAL"
exit 1
fi
else
@ -56,7 +86,7 @@ function CheckEnvironment {
## Check for CONF_FILE_PATH
if [ ! -d "$CONF_FILE_PATH" ]; then
Log "Cannot find conf file path $CONF_FILE_PATH"
Logger "Cannot find conf file path $CONF_FILE_PATH" "CRITICAL"
Usage
fi
}
@ -75,19 +105,19 @@ function Batch {
RERUNS=0
while ([ $MAX_EXECUTION_TIME -gt $SECONDS ] || [ $MAX_EXECUTION_TIME -eq 0 ]) && [ "$RUN" != "" ] && [ $MAX_RERUNS -gt $RERUNS ]
do
Log "Osync instances will be run for: $RUN"
Logger "Osync instances will be run for: $RUN" "NOTICE"
for i in $RUN
do
$OSYNC_EXECUTABLE "$i" $opts
if [ $? != 0 ]; then
Log "Run instance $(basename $i) failed"
Logger "Run instance $(basename $i) failed" "ERROR"
if [ "RUN_AGAIN" == "" ]; then
RUN_AGAIN="$i"
else
RUN_AGAIN=$RUN_AGAIN" $i"
fi
else
Log "Run instance $(basename $i) succeed."
Logger "Run instance $(basename $i) succeed." "NOTICE"
fi
done
RUN="$RUN_AGAIN"
@ -150,12 +180,12 @@ do
Usage
;;
*)
Log "Unknown param '$i'"
Logger "Unknown param '$i'" "CRITICAL"
Usage
;;
esac
done
CheckEnvironment
Log "$(date) Osync batch run"
Logger "$(date) Osync batch run" "NOTICE"
Batch

@ -1,6 +1,6 @@
#!/bin/bash
##### Osync ssh command filter build 2015070203
##### Osync ssh command filter build 2015090801
##### This script should be located in /usr/local/bin in the remote system to sync / backup
##### It will filter the commands that can be run remotely via ssh.
##### Please chmod 755 and chown root:root this file

Loading…
Cancel
Save