mirror of
https://github.com/deajan/obackup.git
synced 2025-05-10 12:13:41 +02:00
Improved logging for execution time
This commit is contained in:
parent
d2ab111f90
commit
0f11faa7c7
@ -10,7 +10,9 @@ CHANGELOG
|
|||||||
|
|
||||||
README: FreeBSD execution needs mailer (not found), sudo missing, bash needed, sed missing (see if StripQuotes mandatory)
|
README: FreeBSD execution needs mailer (not found), sudo missing, bash needed, sed missing (see if StripQuotes mandatory)
|
||||||
|
|
||||||
! XX Dec 2015: obackup v2.0 released
|
! XX Mar 2016: obackup v2.0 released
|
||||||
|
- Improved mail fallback
|
||||||
|
- More logging enhancements
|
||||||
- Improved upgrade script
|
- Improved upgrade script
|
||||||
- Revamped rsync patterns to allow include and exclude patterns
|
- Revamped rsync patterns to allow include and exclude patterns
|
||||||
- Better SQL and file backup task separation (rotate copies and warnings are defined for sql and/or file)
|
- Better SQL and file backup task separation (rotate copies and warnings are defined for sql and/or file)
|
||||||
@ -27,7 +29,7 @@ README: FreeBSD execution needs mailer (not found), sudo missing, bash needed, s
|
|||||||
- Improved Logging
|
- Improved Logging
|
||||||
- Updated obackup to be fully compliant with coding style
|
- Updated obackup to be fully compliant with coding style
|
||||||
- Fixed creation of bogus subdirectories in some cases
|
- Fixed creation of bogus subdirectories in some cases
|
||||||
- A long list of minor improvements
|
- A long list of minor improvements and bug fixes
|
||||||
|
|
||||||
v0-1.x - Jan 2013 - Oct 2015
|
v0-1.x - Jan 2013 - Oct 2015
|
||||||
- New function to kill child processes
|
- New function to kill child processes
|
||||||
|
@ -8,7 +8,7 @@ PROGRAM_VERSION=2.0-pre
|
|||||||
PROGRAM_BUILD=2016030302
|
PROGRAM_BUILD=2016030302
|
||||||
IS_STABLE=no
|
IS_STABLE=no
|
||||||
|
|
||||||
## FUNC_BUILD=2016030303
|
## FUNC_BUILD=2016030401
|
||||||
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
||||||
|
|
||||||
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
|
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
|
||||||
@ -41,6 +41,8 @@ else
|
|||||||
_VERBOSE=1
|
_VERBOSE=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#### MINIMAL-FUNCTION-SET BEGIN ####
|
||||||
|
|
||||||
SCRIPT_PID=$$
|
SCRIPT_PID=$$
|
||||||
|
|
||||||
LOCAL_USER=$(whoami)
|
LOCAL_USER=$(whoami)
|
||||||
@ -154,95 +156,6 @@ function KillChilds {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function TrapError {
|
|
||||||
local job="$0"
|
|
||||||
local line="$1"
|
|
||||||
local code="${2:-1}"
|
|
||||||
if [ $_SILENT -eq 0 ]; then
|
|
||||||
echo -e " /!\ ERROR in ${job}: Near line ${line}, exit code ${code}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function Spinner {
|
|
||||||
if [ $_SILENT -eq 1 ]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
case $toggle
|
|
||||||
in
|
|
||||||
1)
|
|
||||||
echo -n " \ "
|
|
||||||
echo -ne "\r"
|
|
||||||
toggle="2"
|
|
||||||
;;
|
|
||||||
|
|
||||||
2)
|
|
||||||
echo -n " | "
|
|
||||||
echo -ne "\r"
|
|
||||||
toggle="3"
|
|
||||||
;;
|
|
||||||
|
|
||||||
3)
|
|
||||||
echo -n " / "
|
|
||||||
echo -ne "\r"
|
|
||||||
toggle="4"
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
echo -n " - "
|
|
||||||
echo -ne "\r"
|
|
||||||
toggle="1"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
function SedStripQuotes {
|
|
||||||
echo $(echo $1 | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")
|
|
||||||
}
|
|
||||||
|
|
||||||
function StripSingleQuotes {
|
|
||||||
local string="${1}"
|
|
||||||
string="${string/#\'/}" # Remove singlequote if it begins string
|
|
||||||
string="${string/%\'/}" # Remove singlequote if it ends string
|
|
||||||
echo "$string"
|
|
||||||
}
|
|
||||||
|
|
||||||
function StripDoubleQuotes {
|
|
||||||
local string="${1}"
|
|
||||||
string="${string/#\"/}"
|
|
||||||
string="${string/%\"/}"
|
|
||||||
echo "$string"
|
|
||||||
}
|
|
||||||
|
|
||||||
function StripQuotes {
|
|
||||||
local string="${1}"
|
|
||||||
echo "$(StripSingleQuotes $(StripDoubleQuotes $string))"
|
|
||||||
}
|
|
||||||
|
|
||||||
function EscapeSpaces {
|
|
||||||
local string="${1}" # String on which spaces will be escaped
|
|
||||||
echo "${string// /\ }"
|
|
||||||
}
|
|
||||||
|
|
||||||
function IsNumeric {
|
|
||||||
eval "local value=\"${1}\"" # Needed so variable variables can be processed
|
|
||||||
|
|
||||||
local re="^-?[0-9]+([.][0-9]+)?$"
|
|
||||||
if [[ $value =~ $re ]]; then
|
|
||||||
echo 1
|
|
||||||
else
|
|
||||||
echo 0
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function CleanUp {
|
|
||||||
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
|
||||||
|
|
||||||
if [ "$_DEBUG" != "yes" ]; then
|
|
||||||
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function SendAlert {
|
function SendAlert {
|
||||||
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
@ -352,6 +265,97 @@ function SendAlert {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#### MINIMAL-FUNCTION-SET END ####
|
||||||
|
|
||||||
|
function TrapError {
|
||||||
|
local job="$0"
|
||||||
|
local line="$1"
|
||||||
|
local code="${2:-1}"
|
||||||
|
if [ $_SILENT -eq 0 ]; then
|
||||||
|
echo -e " /!\ ERROR in ${job}: Near line ${line}, exit code ${code}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function Spinner {
|
||||||
|
if [ $_SILENT -eq 1 ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $toggle
|
||||||
|
in
|
||||||
|
1)
|
||||||
|
echo -n " \ "
|
||||||
|
echo -ne "\r"
|
||||||
|
toggle="2"
|
||||||
|
;;
|
||||||
|
|
||||||
|
2)
|
||||||
|
echo -n " | "
|
||||||
|
echo -ne "\r"
|
||||||
|
toggle="3"
|
||||||
|
;;
|
||||||
|
|
||||||
|
3)
|
||||||
|
echo -n " / "
|
||||||
|
echo -ne "\r"
|
||||||
|
toggle="4"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo -n " - "
|
||||||
|
echo -ne "\r"
|
||||||
|
toggle="1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
function SedStripQuotes {
|
||||||
|
echo $(echo $1 | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")
|
||||||
|
}
|
||||||
|
|
||||||
|
function StripSingleQuotes {
|
||||||
|
local string="${1}"
|
||||||
|
string="${string/#\'/}" # Remove singlequote if it begins string
|
||||||
|
string="${string/%\'/}" # Remove singlequote if it ends string
|
||||||
|
echo "$string"
|
||||||
|
}
|
||||||
|
|
||||||
|
function StripDoubleQuotes {
|
||||||
|
local string="${1}"
|
||||||
|
string="${string/#\"/}"
|
||||||
|
string="${string/%\"/}"
|
||||||
|
echo "$string"
|
||||||
|
}
|
||||||
|
|
||||||
|
function StripQuotes {
|
||||||
|
local string="${1}"
|
||||||
|
echo "$(StripSingleQuotes $(StripDoubleQuotes $string))"
|
||||||
|
}
|
||||||
|
|
||||||
|
function EscapeSpaces {
|
||||||
|
local string="${1}" # String on which spaces will be escaped
|
||||||
|
echo "${string// /\ }"
|
||||||
|
}
|
||||||
|
|
||||||
|
function IsNumeric {
|
||||||
|
eval "local value=\"${1}\"" # Needed so variable variables can be processed
|
||||||
|
|
||||||
|
local re="^-?[0-9]+([.][0-9]+)?$"
|
||||||
|
if [[ $value =~ $re ]]; then
|
||||||
|
echo 1
|
||||||
|
else
|
||||||
|
echo 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function CleanUp {
|
||||||
|
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
|
if [ "$_DEBUG" != "yes" ]; then
|
||||||
|
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function LoadConfigFile {
|
function LoadConfigFile {
|
||||||
local config_file="${1}"
|
local config_file="${1}"
|
||||||
__CheckArguments 1 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
__CheckArguments 1 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
@ -494,13 +498,13 @@ function WaitForTaskCompletion {
|
|||||||
fi
|
fi
|
||||||
if [ $exec_time -gt $soft_max_time ]; then
|
if [ $exec_time -gt $soft_max_time ]; then
|
||||||
if [ $soft_alert -eq 0 ] && [ $soft_max_time -ne 0 ]; then
|
if [ $soft_alert -eq 0 ] && [ $soft_max_time -ne 0 ]; then
|
||||||
Logger "Max soft execution time exceeded for task." "WARN"
|
Logger "Max soft execution time exceeded for task [$caller_name]." "WARN"
|
||||||
soft_alert=1
|
soft_alert=1
|
||||||
SendAlert
|
SendAlert
|
||||||
|
|
||||||
fi
|
fi
|
||||||
if [ $exec_time -gt $hard_max_time ] && [ $hard_max_time -ne 0 ]; then
|
if [ $exec_time -gt $hard_max_time ] && [ $hard_max_time -ne 0 ]; then
|
||||||
Logger "Max hard execution time exceeded for task. Stopping task execution." "ERROR"
|
Logger "Max hard execution time exceeded for task [$caller_name]. Stopping task execution." "ERROR"
|
||||||
kill -s SIGTERM $pid
|
kill -s SIGTERM $pid
|
||||||
if [ $? == 0 ]; then
|
if [ $? == 0 ]; then
|
||||||
Logger "Task stopped succesfully" "NOTICE"
|
Logger "Task stopped succesfully" "NOTICE"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
## FUNC_BUILD=2016030303
|
## FUNC_BUILD=2016030401
|
||||||
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
||||||
|
|
||||||
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
|
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
|
||||||
@ -31,6 +31,8 @@ else
|
|||||||
_VERBOSE=1
|
_VERBOSE=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#### MINIMAL-FUNCTION-SET BEGIN ####
|
||||||
|
|
||||||
SCRIPT_PID=$$
|
SCRIPT_PID=$$
|
||||||
|
|
||||||
LOCAL_USER=$(whoami)
|
LOCAL_USER=$(whoami)
|
||||||
@ -144,95 +146,6 @@ function KillChilds {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function TrapError {
|
|
||||||
local job="$0"
|
|
||||||
local line="$1"
|
|
||||||
local code="${2:-1}"
|
|
||||||
if [ $_SILENT -eq 0 ]; then
|
|
||||||
echo -e " /!\ ERROR in ${job}: Near line ${line}, exit code ${code}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function Spinner {
|
|
||||||
if [ $_SILENT -eq 1 ]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
case $toggle
|
|
||||||
in
|
|
||||||
1)
|
|
||||||
echo -n " \ "
|
|
||||||
echo -ne "\r"
|
|
||||||
toggle="2"
|
|
||||||
;;
|
|
||||||
|
|
||||||
2)
|
|
||||||
echo -n " | "
|
|
||||||
echo -ne "\r"
|
|
||||||
toggle="3"
|
|
||||||
;;
|
|
||||||
|
|
||||||
3)
|
|
||||||
echo -n " / "
|
|
||||||
echo -ne "\r"
|
|
||||||
toggle="4"
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
echo -n " - "
|
|
||||||
echo -ne "\r"
|
|
||||||
toggle="1"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
function SedStripQuotes {
|
|
||||||
echo $(echo $1 | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")
|
|
||||||
}
|
|
||||||
|
|
||||||
function StripSingleQuotes {
|
|
||||||
local string="${1}"
|
|
||||||
string="${string/#\'/}" # Remove singlequote if it begins string
|
|
||||||
string="${string/%\'/}" # Remove singlequote if it ends string
|
|
||||||
echo "$string"
|
|
||||||
}
|
|
||||||
|
|
||||||
function StripDoubleQuotes {
|
|
||||||
local string="${1}"
|
|
||||||
string="${string/#\"/}"
|
|
||||||
string="${string/%\"/}"
|
|
||||||
echo "$string"
|
|
||||||
}
|
|
||||||
|
|
||||||
function StripQuotes {
|
|
||||||
local string="${1}"
|
|
||||||
echo "$(StripSingleQuotes $(StripDoubleQuotes $string))"
|
|
||||||
}
|
|
||||||
|
|
||||||
function EscapeSpaces {
|
|
||||||
local string="${1}" # String on which spaces will be escaped
|
|
||||||
echo "${string// /\ }"
|
|
||||||
}
|
|
||||||
|
|
||||||
function IsNumeric {
|
|
||||||
eval "local value=\"${1}\"" # Needed so variable variables can be processed
|
|
||||||
|
|
||||||
local re="^-?[0-9]+([.][0-9]+)?$"
|
|
||||||
if [[ $value =~ $re ]]; then
|
|
||||||
echo 1
|
|
||||||
else
|
|
||||||
echo 0
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function CleanUp {
|
|
||||||
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
|
||||||
|
|
||||||
if [ "$_DEBUG" != "yes" ]; then
|
|
||||||
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function SendAlert {
|
function SendAlert {
|
||||||
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
@ -342,6 +255,97 @@ function SendAlert {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#### MINIMAL-FUNCTION-SET END ####
|
||||||
|
|
||||||
|
function TrapError {
|
||||||
|
local job="$0"
|
||||||
|
local line="$1"
|
||||||
|
local code="${2:-1}"
|
||||||
|
if [ $_SILENT -eq 0 ]; then
|
||||||
|
echo -e " /!\ ERROR in ${job}: Near line ${line}, exit code ${code}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function Spinner {
|
||||||
|
if [ $_SILENT -eq 1 ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $toggle
|
||||||
|
in
|
||||||
|
1)
|
||||||
|
echo -n " \ "
|
||||||
|
echo -ne "\r"
|
||||||
|
toggle="2"
|
||||||
|
;;
|
||||||
|
|
||||||
|
2)
|
||||||
|
echo -n " | "
|
||||||
|
echo -ne "\r"
|
||||||
|
toggle="3"
|
||||||
|
;;
|
||||||
|
|
||||||
|
3)
|
||||||
|
echo -n " / "
|
||||||
|
echo -ne "\r"
|
||||||
|
toggle="4"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo -n " - "
|
||||||
|
echo -ne "\r"
|
||||||
|
toggle="1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
function SedStripQuotes {
|
||||||
|
echo $(echo $1 | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")
|
||||||
|
}
|
||||||
|
|
||||||
|
function StripSingleQuotes {
|
||||||
|
local string="${1}"
|
||||||
|
string="${string/#\'/}" # Remove singlequote if it begins string
|
||||||
|
string="${string/%\'/}" # Remove singlequote if it ends string
|
||||||
|
echo "$string"
|
||||||
|
}
|
||||||
|
|
||||||
|
function StripDoubleQuotes {
|
||||||
|
local string="${1}"
|
||||||
|
string="${string/#\"/}"
|
||||||
|
string="${string/%\"/}"
|
||||||
|
echo "$string"
|
||||||
|
}
|
||||||
|
|
||||||
|
function StripQuotes {
|
||||||
|
local string="${1}"
|
||||||
|
echo "$(StripSingleQuotes $(StripDoubleQuotes $string))"
|
||||||
|
}
|
||||||
|
|
||||||
|
function EscapeSpaces {
|
||||||
|
local string="${1}" # String on which spaces will be escaped
|
||||||
|
echo "${string// /\ }"
|
||||||
|
}
|
||||||
|
|
||||||
|
function IsNumeric {
|
||||||
|
eval "local value=\"${1}\"" # Needed so variable variables can be processed
|
||||||
|
|
||||||
|
local re="^-?[0-9]+([.][0-9]+)?$"
|
||||||
|
if [[ $value =~ $re ]]; then
|
||||||
|
echo 1
|
||||||
|
else
|
||||||
|
echo 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function CleanUp {
|
||||||
|
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
|
if [ "$_DEBUG" != "yes" ]; then
|
||||||
|
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function LoadConfigFile {
|
function LoadConfigFile {
|
||||||
local config_file="${1}"
|
local config_file="${1}"
|
||||||
__CheckArguments 1 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
__CheckArguments 1 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
@ -484,13 +488,13 @@ function WaitForTaskCompletion {
|
|||||||
fi
|
fi
|
||||||
if [ $exec_time -gt $soft_max_time ]; then
|
if [ $exec_time -gt $soft_max_time ]; then
|
||||||
if [ $soft_alert -eq 0 ] && [ $soft_max_time -ne 0 ]; then
|
if [ $soft_alert -eq 0 ] && [ $soft_max_time -ne 0 ]; then
|
||||||
Logger "Max soft execution time exceeded for task." "WARN"
|
Logger "Max soft execution time exceeded for task [$caller_name]." "WARN"
|
||||||
soft_alert=1
|
soft_alert=1
|
||||||
SendAlert
|
SendAlert
|
||||||
|
|
||||||
fi
|
fi
|
||||||
if [ $exec_time -gt $hard_max_time ] && [ $hard_max_time -ne 0 ]; then
|
if [ $exec_time -gt $hard_max_time ] && [ $hard_max_time -ne 0 ]; then
|
||||||
Logger "Max hard execution time exceeded for task. Stopping task execution." "ERROR"
|
Logger "Max hard execution time exceeded for task [$caller_name]. Stopping task execution." "ERROR"
|
||||||
kill -s SIGTERM $pid
|
kill -s SIGTERM $pid
|
||||||
if [ $? == 0 ]; then
|
if [ $? == 0 ]; then
|
||||||
Logger "Task stopped succesfully" "NOTICE"
|
Logger "Task stopped succesfully" "NOTICE"
|
||||||
|
186
obackup.sh
186
obackup.sh
@ -8,7 +8,7 @@ PROGRAM_VERSION=2.0-pre
|
|||||||
PROGRAM_BUILD=2016030302
|
PROGRAM_BUILD=2016030302
|
||||||
IS_STABLE=no
|
IS_STABLE=no
|
||||||
|
|
||||||
## FUNC_BUILD=2016030303
|
## FUNC_BUILD=2016030401
|
||||||
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
||||||
|
|
||||||
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
|
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
|
||||||
@ -37,6 +37,8 @@ else
|
|||||||
_VERBOSE=1
|
_VERBOSE=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#### MINIMAL-FUNCTION-SET BEGIN ####
|
||||||
|
|
||||||
SCRIPT_PID=$$
|
SCRIPT_PID=$$
|
||||||
|
|
||||||
LOCAL_USER=$(whoami)
|
LOCAL_USER=$(whoami)
|
||||||
@ -144,94 +146,6 @@ function KillChilds {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function TrapError {
|
|
||||||
local job="$0"
|
|
||||||
local line="$1"
|
|
||||||
local code="${2:-1}"
|
|
||||||
if [ $_SILENT -eq 0 ]; then
|
|
||||||
echo -e " /!\ ERROR in ${job}: Near line ${line}, exit code ${code}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function Spinner {
|
|
||||||
if [ $_SILENT -eq 1 ]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
case $toggle
|
|
||||||
in
|
|
||||||
1)
|
|
||||||
echo -n " \ "
|
|
||||||
echo -ne "\r"
|
|
||||||
toggle="2"
|
|
||||||
;;
|
|
||||||
|
|
||||||
2)
|
|
||||||
echo -n " | "
|
|
||||||
echo -ne "\r"
|
|
||||||
toggle="3"
|
|
||||||
;;
|
|
||||||
|
|
||||||
3)
|
|
||||||
echo -n " / "
|
|
||||||
echo -ne "\r"
|
|
||||||
toggle="4"
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
echo -n " - "
|
|
||||||
echo -ne "\r"
|
|
||||||
toggle="1"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
function SedStripQuotes {
|
|
||||||
echo $(echo $1 | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")
|
|
||||||
}
|
|
||||||
|
|
||||||
function StripSingleQuotes {
|
|
||||||
local string="${1}"
|
|
||||||
string="${string/#\'/}" # Remove singlequote if it begins string
|
|
||||||
string="${string/%\'/}" # Remove singlequote if it ends string
|
|
||||||
echo "$string"
|
|
||||||
}
|
|
||||||
|
|
||||||
function StripDoubleQuotes {
|
|
||||||
local string="${1}"
|
|
||||||
string="${string/#\"/}"
|
|
||||||
string="${string/%\"/}"
|
|
||||||
echo "$string"
|
|
||||||
}
|
|
||||||
|
|
||||||
function StripQuotes {
|
|
||||||
local string="${1}"
|
|
||||||
echo "$(StripSingleQuotes $(StripDoubleQuotes $string))"
|
|
||||||
}
|
|
||||||
|
|
||||||
function EscapeSpaces {
|
|
||||||
local string="${1}" # String on which spaces will be escaped
|
|
||||||
echo "${string// /\ }"
|
|
||||||
}
|
|
||||||
|
|
||||||
function IsNumeric {
|
|
||||||
eval "local value=\"${1}\"" # Needed so variable variables can be processed
|
|
||||||
|
|
||||||
local re="^-?[0-9]+([.][0-9]+)?$"
|
|
||||||
if [[ $value =~ $re ]]; then
|
|
||||||
echo 1
|
|
||||||
else
|
|
||||||
echo 0
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function CleanUp {
|
|
||||||
|
|
||||||
if [ "$_DEBUG" != "yes" ]; then
|
|
||||||
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function SendAlert {
|
function SendAlert {
|
||||||
|
|
||||||
local mail_no_attachment=
|
local mail_no_attachment=
|
||||||
@ -340,6 +254,96 @@ function SendAlert {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#### MINIMAL-FUNCTION-SET END ####
|
||||||
|
|
||||||
|
function TrapError {
|
||||||
|
local job="$0"
|
||||||
|
local line="$1"
|
||||||
|
local code="${2:-1}"
|
||||||
|
if [ $_SILENT -eq 0 ]; then
|
||||||
|
echo -e " /!\ ERROR in ${job}: Near line ${line}, exit code ${code}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function Spinner {
|
||||||
|
if [ $_SILENT -eq 1 ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $toggle
|
||||||
|
in
|
||||||
|
1)
|
||||||
|
echo -n " \ "
|
||||||
|
echo -ne "\r"
|
||||||
|
toggle="2"
|
||||||
|
;;
|
||||||
|
|
||||||
|
2)
|
||||||
|
echo -n " | "
|
||||||
|
echo -ne "\r"
|
||||||
|
toggle="3"
|
||||||
|
;;
|
||||||
|
|
||||||
|
3)
|
||||||
|
echo -n " / "
|
||||||
|
echo -ne "\r"
|
||||||
|
toggle="4"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo -n " - "
|
||||||
|
echo -ne "\r"
|
||||||
|
toggle="1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
function SedStripQuotes {
|
||||||
|
echo $(echo $1 | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")
|
||||||
|
}
|
||||||
|
|
||||||
|
function StripSingleQuotes {
|
||||||
|
local string="${1}"
|
||||||
|
string="${string/#\'/}" # Remove singlequote if it begins string
|
||||||
|
string="${string/%\'/}" # Remove singlequote if it ends string
|
||||||
|
echo "$string"
|
||||||
|
}
|
||||||
|
|
||||||
|
function StripDoubleQuotes {
|
||||||
|
local string="${1}"
|
||||||
|
string="${string/#\"/}"
|
||||||
|
string="${string/%\"/}"
|
||||||
|
echo "$string"
|
||||||
|
}
|
||||||
|
|
||||||
|
function StripQuotes {
|
||||||
|
local string="${1}"
|
||||||
|
echo "$(StripSingleQuotes $(StripDoubleQuotes $string))"
|
||||||
|
}
|
||||||
|
|
||||||
|
function EscapeSpaces {
|
||||||
|
local string="${1}" # String on which spaces will be escaped
|
||||||
|
echo "${string// /\ }"
|
||||||
|
}
|
||||||
|
|
||||||
|
function IsNumeric {
|
||||||
|
eval "local value=\"${1}\"" # Needed so variable variables can be processed
|
||||||
|
|
||||||
|
local re="^-?[0-9]+([.][0-9]+)?$"
|
||||||
|
if [[ $value =~ $re ]]; then
|
||||||
|
echo 1
|
||||||
|
else
|
||||||
|
echo 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function CleanUp {
|
||||||
|
|
||||||
|
if [ "$_DEBUG" != "yes" ]; then
|
||||||
|
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function LoadConfigFile {
|
function LoadConfigFile {
|
||||||
local config_file="${1}"
|
local config_file="${1}"
|
||||||
|
|
||||||
@ -477,13 +481,13 @@ function WaitForTaskCompletion {
|
|||||||
fi
|
fi
|
||||||
if [ $exec_time -gt $soft_max_time ]; then
|
if [ $exec_time -gt $soft_max_time ]; then
|
||||||
if [ $soft_alert -eq 0 ] && [ $soft_max_time -ne 0 ]; then
|
if [ $soft_alert -eq 0 ] && [ $soft_max_time -ne 0 ]; then
|
||||||
Logger "Max soft execution time exceeded for task." "WARN"
|
Logger "Max soft execution time exceeded for task [$caller_name]." "WARN"
|
||||||
soft_alert=1
|
soft_alert=1
|
||||||
SendAlert
|
SendAlert
|
||||||
|
|
||||||
fi
|
fi
|
||||||
if [ $exec_time -gt $hard_max_time ] && [ $hard_max_time -ne 0 ]; then
|
if [ $exec_time -gt $hard_max_time ] && [ $hard_max_time -ne 0 ]; then
|
||||||
Logger "Max hard execution time exceeded for task. Stopping task execution." "ERROR"
|
Logger "Max hard execution time exceeded for task [$caller_name]. Stopping task execution." "ERROR"
|
||||||
kill -s SIGTERM $pid
|
kill -s SIGTERM $pid
|
||||||
if [ $? == 0 ]; then
|
if [ $? == 0 ]; then
|
||||||
Logger "Task stopped succesfully" "NOTICE"
|
Logger "Task stopped succesfully" "NOTICE"
|
||||||
|
Loading…
Reference in New Issue
Block a user