Rebuilt targets

pull/166/head
deajan 5 years ago
parent 0f5bed992f
commit 5e42a088d0

@ -43,7 +43,7 @@ CONFIG_FILE_REVISION_REQUIRED=1.3.0
# CleanUp no #__WITH_PARANOIA_DEBUG
_OFUNCTIONS_VERSION=2.3.0-RC2
_OFUNCTIONS_BUILD=2019021401
_OFUNCTIONS_BUILD=2019031501
_OFUNCTIONS_BOOTSTRAP=true
if ! type "$BASH" > /dev/null; then
@ -195,7 +195,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi
@ -402,11 +402,11 @@ function KillChilds {
if kill -0 "$pid" > /dev/null 2>&1; then
kill -s TERM "$pid"
Logger "Sent SIGTERM to process [$pid]." "DEBUG"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
sleep 15
Logger "Sending SIGTERM to process [$pid] failed." "DEBUG"
kill -9 "$pid"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Sending SIGKILL to process [$pid] failed." "DEBUG"
return 1
fi # Simplify the return 0 logic here
@ -432,7 +432,7 @@ function KillAllChilds {
IFS=';' read -a pidsArray <<< "$pids"
for pid in "${pidsArray[@]}"; do
KillChilds $pid $self
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
errorcount=$((errorcount+1))
fi
done
@ -469,10 +469,10 @@ function GenericTrapQuit {
# osync/obackup/pmocr script specific mail alert function, use SendEmail function for generic mail sending
function SendAlert {
local runAlert="${1:-false}" # Specifies if current message is sent while running or at the end of a run
local attachment="${2:-true}" # Should we send the log file as attachment
__CheckArguments 0-1 $# "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 0-2 $# "$@" #__WITH_PARANOIA_DEBUG
local attachment
local attachmentFile
local subject
local body
@ -486,14 +486,17 @@ function SendAlert {
return 0
fi
eval "cat \"$LOG_FILE\" $COMPRESSION_PROGRAM > $ALERT_LOG_FILE"
if [ $? != 0 ]; then
attachment=false
else
attachment=true
fi
if [ $attachment == true ]; then
attachmentFile="$LOG_FILE"
if type "$COMPRESSION_PROGRAM" > /dev/null 2>&1; then
eval "cat \"$LOG_FILE\" \"$COMPRESSION_PROGRAM\" > \"$ALERT_LOG_FILE\""
if [ $? -eq 0 ]; then
attachmentFile="$ALERT_LOG_FILE"
fi
fi
fi
body="$MAIL_ALERT_MSG"$'\n\n'"Last 1000 lines of current log"$'\n\n'"$(tail -n 1000 $RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log)"
body="$MAIL_ALERT_MSG"$'\n\n'"Last 1000 lines of current log"$'\n\n'"$(tail -n 1000 "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log")"
if [ $ERROR_ALERT == true ]; then
subject="Error alert for $INSTANCE_ID"
@ -509,10 +512,6 @@ function SendAlert {
subject="Finished run - $subject"
fi
if [ "$attachment" == true ]; then
attachmentFile="$ALERT_LOG_FILE"
fi
SendEmail "$subject" "$body" "$DESTINATION_MAILS" "$attachmentFile" "$SENDER_MAIL" "$SMTP_SERVER" "$SMTP_PORT" "$SMTP_ENCRYPTION" "$SMTP_USER" "$SMTP_PASSWORD"
# Delete tmp log file
@ -561,8 +560,7 @@ function SendEmail {
local i
if [ "${destinationMails}" != "" ]; then
# Not quoted since we split at space character, and emails cannot contain spaces
for i in ${destinationMails}; do
for i in "${destinationMails[@]}"; do
if [ $(CheckRFC822 "$i") -ne 1 ]; then
Logger "Given email [$i] does not seem to be valid." "WARN"
fi
@ -603,7 +601,7 @@ function SendEmail {
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) -f "$senderMail" -S "$smtpServer:$smtpPort" -au"$smtpUser" -ap"$smtpPassword" "$destinationMails"
fi
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot send alert mail via $(type -p sendmail) !!!" "WARN"
# Do not bother try other mail systems with busybox
return 1
@ -619,7 +617,7 @@ function SendEmail {
if type mutt > /dev/null 2>&1 ; then
# We need to replace spaces with comma in order for mutt to be able to process multiple destinations
echo "$message" | $(type -p mutt) -x -s "$subject" "${destinationMails// /,}" $attachment_command
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot send mail via $(type -p mutt) !!!" "WARN"
else
Logger "Sent mail using mutt." "NOTICE"
@ -641,10 +639,10 @@ function SendEmail {
fi
echo "$message" | $(type -p mail) $attachment_command -s "$subject" "$destinationMails"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot send mail via $(type -p mail) with attachments !!!" "WARN"
echo "$message" | $(type -p mail) -s "$subject" "$destinationMails"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot send mail via $(type -p mail) without attachments !!!" "WARN"
else
Logger "Sent mail using mail command without attachment." "NOTICE"
@ -658,7 +656,7 @@ function SendEmail {
if type sendmail > /dev/null 2>&1 ; then
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) "$destinationMails"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot send mail via $(type -p sendmail) !!!" "WARN"
else
Logger "Sent mail using sendmail command without attachment." "NOTICE"
@ -692,7 +690,7 @@ function SendEmail {
auth_string="-auth -user \"$smtpUser\" -pass \"$smtpPassword\""
fi
$(type mailsend.exe) -f "$senderMail" -t "$destinationMails" -sub "$subject" -M "$message" -attach "$attachment" -smtp "$smtpServer" -port "$smtpPort" $encryption_string $auth_string
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot send mail via $(type mailsend.exe) !!!" "WARN"
else
Logger "Sent mail using mailsend.exe command with attachment." "NOTICE"
@ -703,7 +701,7 @@ function SendEmail {
# pfSense specific
if [ -f /usr/local/bin/mail.php ]; then
echo "$message" | /usr/local/bin/mail.php -s="$subject"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot send mail via /usr/local/bin/mail.php (pfsense) !!!" "WARN"
else
Logger "Sent mail using pfSense mail.php." "NOTICE"
@ -729,7 +727,7 @@ function LoadConfigFile {
local configFile="${1}"
local revisionRequired="${2}"
__CheckArguments 1 $# "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 2 $# "$@" #__WITH_PARANOIA_DEBUG
local revisionPresent
@ -743,8 +741,7 @@ function LoadConfigFile {
revisionPresent=$(GetConfFileValue "$configFile" "CONFIG_FILE_REVISION" true)
if [ "$(IsNumeric $revisionPresent)" -eq 0 ]; then
Logger "CONFIG_FILE_REVISION does not seem numeric [$revisionPresent]." "DEBUG"
fi
if [ "$revisionRequired" != "" ]; then
elif [ "$revisionRequired" != "" ]; then
if [ $(VerComp "$revisionPresent" "$revisionRequired") -eq 2 ]; then
Logger "Configuration file seems out of date. Required version [$revisionRequired]. Actual version [$revisionPresent]." "CRITICAL"
exit 1
@ -997,13 +994,18 @@ function ExecTasks {
fi
if [ $keepLogging -ne 0 ]; then
# This log solely exists for readability purposes before having next set of logs
if [ ${#pidsArray[@]} -eq $numberOfProcesses ] && [ $log_ttime -eq 0 ]; then
log_ttime=$exec_time
Logger "There are $((mainItemCount-counter+postponedItemCount)) / $mainItemCount tasks in the queue of which $postponedItemCount are postponed. Currently, ${#pidsArray[@]} tasks running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE"
fi
if [ $(((exec_time + 1) % keepLogging)) -eq 0 ]; then
if [ $log_ttime -ne $exec_time ]; then # Fix when sleep time lower than 1 second
log_ttime=$exec_time
if [ $functionMode == "Wait" ]; then
if [ $functionMode == "WaitForTaskCompletion" ]; then
Logger "Current tasks still running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE"
elif [ $functionMode == "ParallelExec" ]; then
Logger "There are $((mainItemCount-counter+postponedItemCount)) / $mainItemCount tasks in the queue. Currently, ${#pidsArray[@]} tasks running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE"
Logger "There are $((mainItemCount-counter+postponedItemCount)) / $mainItemCount tasks in the queue of which $postponedItemCount are postponed. Currently, ${#pidsArray[@]} tasks running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE"
fi
fi
fi
@ -1023,7 +1025,7 @@ function ExecTasks {
fi
for pid in "${pidsArray[@]}"; do
KillChilds $pid true
if [ $? == 0 ]; then
if [ $? -eq 0 ]; then
Logger "Task with pid [$pid] stopped successfully." "NOTICE"
else
if [ $noErrorLogsAtAll != true ]; then
@ -1076,7 +1078,7 @@ function ExecTasks {
fi
fi
KillChilds $pid true
if [ $? == 0 ]; then
if [ $? -eq 0 ]; then
Logger "Command with pid [$pid] stopped successfully." "NOTICE"
else
if [ $noErrorLogsAtAll != true ]; then
@ -1104,7 +1106,7 @@ function ExecTasks {
Logger "Command was [${commandsArrayPid[$pid]}]." "ERROR"
fi
if [ -f "${commandsArrayOutput[$pid]}" ]; then
Logger "Command output was [\$(cat ${commandsArrayOutput[$pid]})\n]." "ERROR"
Logger "Command output was [$(cat ${commandsArrayOutput[$pid]})\n]." "ERROR"
fi
fi
errorcount=$((errorcount+1))
@ -1250,11 +1252,11 @@ function ExecTasks {
if [ $executeCommand == true ]; then
Logger "Running command [$currentCommand]." "DEBUG"
randomOutputName=$(date '+%Y%m%dT%H%M%S').$(PoorMansRandomGenerator 5)
eval "$currentCommand" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$randomOutputName.$SCRIPT_PID.$TSTAMP" 2>&1 &
eval "$currentCommand" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$id.$pid.$randomOutputName.$SCRIPT_PID.$TSTAMP" 2>&1 &
pid=$!
pidsArray+=($pid)
commandsArrayPid[$pid]="$currentCommand"
commandsArrayOutput[$pid]="$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$randomOutputName.$SCRIPT_PID.$TSTAMP"
commandsArrayOutput[$pid]="$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$id.$pid.$randomOutputName.$SCRIPT_PID.$TSTAMP"
# Initialize pid execution time array
pidsTimeArray[$pid]=0
else
@ -1453,9 +1455,9 @@ function GetLocalOS {
localOsVar="Microsoft"
else
localOsVar="$(uname -spior 2>&1)"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
localOsVar="$(uname -v 2>&1)"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
localOsVar="$(uname)"
fi
fi
@ -1629,9 +1631,9 @@ function GetOs {
localOsVar="Microsoft"
else
localOsVar="$(uname -spior 2>&1)"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
localOsVar="$(uname -v 2>&1)"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
localOsVar="$(uname)"
fi
fi
@ -1678,7 +1680,7 @@ function GetOs {
GetOs
ENDSSH
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot connect to remote system [$REMOTE_HOST] port [$REMOTE_PORT]." "CRITICAL"
if [ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" ]; then
Logger "$(cat "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP")" "ERROR"
@ -1860,7 +1862,7 @@ function CheckConnectivityRemoteHost {
ExecTasks $! "${FUNCNAME[0]}" false 0 0 60 180 true $SLEEP_TIME $KEEP_LOGGING
#ExecTasks "${FUNCNAME[0]}" 0 0 60 180 $SLEEP_TIME $KEEP_LOGGING true true false false 1 $!
retval=$?
if [ $retval != 0 ]; then
if [ $retval -ne 0 ]; then
Logger "Cannot ping [$REMOTE_HOST]. Return code [$retval]." "WARN"
return $retval
fi
@ -1885,7 +1887,7 @@ function CheckConnectivity3rdPartyHosts {
ExecTasks $! "${FUNCNAME[0]}" false 0 0 60 180 true $SLEEP_TIME $KEEP_LOGGING
#ExecTasks "${FUNCNAME[0]}" 0 0 180 360 $SLEEP_TIME $KEEP_LOGGING true true false false 1 $!
retval=$?
if [ $retval != 0 ]; then
if [ $retval -ne 0 ]; then
Logger "Cannot ping 3rd party host [$i]. Return code [$retval]." "NOTICE"
else
remote3rdPartySuccess=true
@ -2311,7 +2313,7 @@ function GetConfFileValue () {
local value
value=$(grep "^$name=" "$file")
if [ $? == 0 ]; then
if [ $? -eq 0 ]; then
value="${value##*=}"
echo "$value"
else
@ -2753,7 +2755,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi
@ -3119,7 +3121,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi
@ -3734,7 +3736,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi
@ -4369,7 +4371,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi
@ -5323,7 +5325,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi
@ -5597,7 +5599,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi

@ -10,7 +10,7 @@ PROGRAM_BINARY=$PROGRAM".sh"
PROGRAM_BATCH=$PROGRAM"-batch.sh"
SSH_FILTER="ssh_filter.sh"
SCRIPT_BUILD=201902601
SCRIPT_BUILD=2019022601
INSTANCE_ID="installer-$SCRIPT_BUILD"
## osync / obackup / pmocr / zsnap install script
@ -18,7 +18,7 @@ INSTANCE_ID="installer-$SCRIPT_BUILD"
## Please adapt this to fit your distro needs
_OFUNCTIONS_VERSION=2.3.0-RC2
_OFUNCTIONS_BUILD=2019021401
_OFUNCTIONS_BUILD=2019031501
_OFUNCTIONS_BOOTSTRAP=true
if ! type "$BASH" > /dev/null; then
@ -166,7 +166,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi
@ -362,11 +362,11 @@ function KillChilds {
if kill -0 "$pid" > /dev/null 2>&1; then
kill -s TERM "$pid"
Logger "Sent SIGTERM to process [$pid]." "DEBUG"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
sleep 15
Logger "Sending SIGTERM to process [$pid] failed." "DEBUG"
kill -9 "$pid"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Sending SIGKILL to process [$pid] failed." "DEBUG"
return 1
fi # Simplify the return 0 logic here
@ -391,7 +391,7 @@ function KillAllChilds {
IFS=';' read -a pidsArray <<< "$pids"
for pid in "${pidsArray[@]}"; do
KillChilds $pid $self
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
errorcount=$((errorcount+1))
fi
done
@ -527,9 +527,9 @@ function GetLocalOS {
localOsVar="Microsoft"
else
localOsVar="$(uname -spior 2>&1)"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
localOsVar="$(uname -v 2>&1)"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
localOsVar="$(uname)"
fi
fi
@ -623,7 +623,7 @@ function GetConfFileValue () {
local value
value=$(grep "^$name=" "$file")
if [ $? == 0 ]; then
if [ $? -eq 0 ]; then
value="${value##*=}"
echo "$value"
else

@ -58,7 +58,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi

@ -14,7 +14,7 @@ CONFIG_FILE_REVISION_REQUIRED=1.3.0
_OFUNCTIONS_VERSION=2.3.0-RC2
_OFUNCTIONS_BUILD=2019021401
_OFUNCTIONS_BUILD=2019031501
_OFUNCTIONS_BOOTSTRAP=true
if ! type "$BASH" > /dev/null; then
@ -162,7 +162,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi
@ -358,11 +358,11 @@ function KillChilds {
if kill -0 "$pid" > /dev/null 2>&1; then
kill -s TERM "$pid"
Logger "Sent SIGTERM to process [$pid]." "DEBUG"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
sleep 15
Logger "Sending SIGTERM to process [$pid] failed." "DEBUG"
kill -9 "$pid"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Sending SIGKILL to process [$pid] failed." "DEBUG"
return 1
fi # Simplify the return 0 logic here
@ -387,7 +387,7 @@ function KillAllChilds {
IFS=';' read -a pidsArray <<< "$pids"
for pid in "${pidsArray[@]}"; do
KillChilds $pid $self
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
errorcount=$((errorcount+1))
fi
done
@ -424,9 +424,9 @@ function GenericTrapQuit {
# osync/obackup/pmocr script specific mail alert function, use SendEmail function for generic mail sending
function SendAlert {
local runAlert="${1:-false}" # Specifies if current message is sent while running or at the end of a run
local attachment="${2:-true}" # Should we send the log file as attachment
local attachment
local attachmentFile
local subject
local body
@ -440,14 +440,17 @@ function SendAlert {
return 0
fi
eval "cat \"$LOG_FILE\" $COMPRESSION_PROGRAM > $ALERT_LOG_FILE"
if [ $? != 0 ]; then
attachment=false
else
attachment=true
fi
if [ $attachment == true ]; then
attachmentFile="$LOG_FILE"
if type "$COMPRESSION_PROGRAM" > /dev/null 2>&1; then
eval "cat \"$LOG_FILE\" \"$COMPRESSION_PROGRAM\" > \"$ALERT_LOG_FILE\""
if [ $? -eq 0 ]; then
attachmentFile="$ALERT_LOG_FILE"
fi
fi
fi
body="$MAIL_ALERT_MSG"$'\n\n'"Last 1000 lines of current log"$'\n\n'"$(tail -n 1000 $RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log)"
body="$MAIL_ALERT_MSG"$'\n\n'"Last 1000 lines of current log"$'\n\n'"$(tail -n 1000 "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log")"
if [ $ERROR_ALERT == true ]; then
subject="Error alert for $INSTANCE_ID"
@ -463,10 +466,6 @@ function SendAlert {
subject="Finished run - $subject"
fi
if [ "$attachment" == true ]; then
attachmentFile="$ALERT_LOG_FILE"
fi
SendEmail "$subject" "$body" "$DESTINATION_MAILS" "$attachmentFile" "$SENDER_MAIL" "$SMTP_SERVER" "$SMTP_PORT" "$SMTP_ENCRYPTION" "$SMTP_USER" "$SMTP_PASSWORD"
# Delete tmp log file
@ -514,8 +513,7 @@ function SendEmail {
local i
if [ "${destinationMails}" != "" ]; then
# Not quoted since we split at space character, and emails cannot contain spaces
for i in ${destinationMails}; do
for i in "${destinationMails[@]}"; do
if [ $(CheckRFC822 "$i") -ne 1 ]; then
Logger "Given email [$i] does not seem to be valid." "WARN"
fi
@ -556,7 +554,7 @@ function SendEmail {
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) -f "$senderMail" -S "$smtpServer:$smtpPort" -au"$smtpUser" -ap"$smtpPassword" "$destinationMails"
fi
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot send alert mail via $(type -p sendmail) !!!" "WARN"
# Do not bother try other mail systems with busybox
return 1
@ -572,7 +570,7 @@ function SendEmail {
if type mutt > /dev/null 2>&1 ; then
# We need to replace spaces with comma in order for mutt to be able to process multiple destinations
echo "$message" | $(type -p mutt) -x -s "$subject" "${destinationMails// /,}" $attachment_command
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot send mail via $(type -p mutt) !!!" "WARN"
else
Logger "Sent mail using mutt." "NOTICE"
@ -594,10 +592,10 @@ function SendEmail {
fi
echo "$message" | $(type -p mail) $attachment_command -s "$subject" "$destinationMails"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot send mail via $(type -p mail) with attachments !!!" "WARN"
echo "$message" | $(type -p mail) -s "$subject" "$destinationMails"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot send mail via $(type -p mail) without attachments !!!" "WARN"
else
Logger "Sent mail using mail command without attachment." "NOTICE"
@ -611,7 +609,7 @@ function SendEmail {
if type sendmail > /dev/null 2>&1 ; then
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) "$destinationMails"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot send mail via $(type -p sendmail) !!!" "WARN"
else
Logger "Sent mail using sendmail command without attachment." "NOTICE"
@ -645,7 +643,7 @@ function SendEmail {
auth_string="-auth -user \"$smtpUser\" -pass \"$smtpPassword\""
fi
$(type mailsend.exe) -f "$senderMail" -t "$destinationMails" -sub "$subject" -M "$message" -attach "$attachment" -smtp "$smtpServer" -port "$smtpPort" $encryption_string $auth_string
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot send mail via $(type mailsend.exe) !!!" "WARN"
else
Logger "Sent mail using mailsend.exe command with attachment." "NOTICE"
@ -656,7 +654,7 @@ function SendEmail {
# pfSense specific
if [ -f /usr/local/bin/mail.php ]; then
echo "$message" | /usr/local/bin/mail.php -s="$subject"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot send mail via /usr/local/bin/mail.php (pfsense) !!!" "WARN"
else
Logger "Sent mail using pfSense mail.php." "NOTICE"
@ -695,8 +693,7 @@ function LoadConfigFile {
revisionPresent=$(GetConfFileValue "$configFile" "CONFIG_FILE_REVISION" true)
if [ "$(IsNumeric $revisionPresent)" -eq 0 ]; then
Logger "CONFIG_FILE_REVISION does not seem numeric [$revisionPresent]." "DEBUG"
fi
if [ "$revisionRequired" != "" ]; then
elif [ "$revisionRequired" != "" ]; then
if [ $(VerComp "$revisionPresent" "$revisionRequired") -eq 2 ]; then
Logger "Configuration file seems out of date. Required version [$revisionRequired]. Actual version [$revisionPresent]." "CRITICAL"
exit 1
@ -929,13 +926,18 @@ function ExecTasks {
fi
if [ $keepLogging -ne 0 ]; then
# This log solely exists for readability purposes before having next set of logs
if [ ${#pidsArray[@]} -eq $numberOfProcesses ] && [ $log_ttime -eq 0 ]; then
log_ttime=$exec_time
Logger "There are $((mainItemCount-counter+postponedItemCount)) / $mainItemCount tasks in the queue of which $postponedItemCount are postponed. Currently, ${#pidsArray[@]} tasks running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE"
fi
if [ $(((exec_time + 1) % keepLogging)) -eq 0 ]; then
if [ $log_ttime -ne $exec_time ]; then # Fix when sleep time lower than 1 second
log_ttime=$exec_time
if [ $functionMode == "Wait" ]; then
if [ $functionMode == "WaitForTaskCompletion" ]; then
Logger "Current tasks still running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE"
elif [ $functionMode == "ParallelExec" ]; then
Logger "There are $((mainItemCount-counter+postponedItemCount)) / $mainItemCount tasks in the queue. Currently, ${#pidsArray[@]} tasks running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE"
Logger "There are $((mainItemCount-counter+postponedItemCount)) / $mainItemCount tasks in the queue of which $postponedItemCount are postponed. Currently, ${#pidsArray[@]} tasks running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE"
fi
fi
fi
@ -955,7 +957,7 @@ function ExecTasks {
fi
for pid in "${pidsArray[@]}"; do
KillChilds $pid true
if [ $? == 0 ]; then
if [ $? -eq 0 ]; then
Logger "Task with pid [$pid] stopped successfully." "NOTICE"
else
if [ $noErrorLogsAtAll != true ]; then
@ -1008,7 +1010,7 @@ function ExecTasks {
fi
fi
KillChilds $pid true
if [ $? == 0 ]; then
if [ $? -eq 0 ]; then
Logger "Command with pid [$pid] stopped successfully." "NOTICE"
else
if [ $noErrorLogsAtAll != true ]; then
@ -1036,7 +1038,7 @@ function ExecTasks {
Logger "Command was [${commandsArrayPid[$pid]}]." "ERROR"
fi
if [ -f "${commandsArrayOutput[$pid]}" ]; then
Logger "Command output was [\$(cat ${commandsArrayOutput[$pid]})\n]." "ERROR"
Logger "Command output was [$(cat ${commandsArrayOutput[$pid]})\n]." "ERROR"
fi
fi
errorcount=$((errorcount+1))
@ -1175,11 +1177,11 @@ function ExecTasks {
if [ $executeCommand == true ]; then
Logger "Running command [$currentCommand]." "DEBUG"
randomOutputName=$(date '+%Y%m%dT%H%M%S').$(PoorMansRandomGenerator 5)
eval "$currentCommand" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$randomOutputName.$SCRIPT_PID.$TSTAMP" 2>&1 &
eval "$currentCommand" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$id.$pid.$randomOutputName.$SCRIPT_PID.$TSTAMP" 2>&1 &
pid=$!
pidsArray+=($pid)
commandsArrayPid[$pid]="$currentCommand"
commandsArrayOutput[$pid]="$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$randomOutputName.$SCRIPT_PID.$TSTAMP"
commandsArrayOutput[$pid]="$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$id.$pid.$randomOutputName.$SCRIPT_PID.$TSTAMP"
# Initialize pid execution time array
pidsTimeArray[$pid]=0
else
@ -1377,9 +1379,9 @@ function GetLocalOS {
localOsVar="Microsoft"
else
localOsVar="$(uname -spior 2>&1)"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
localOsVar="$(uname -v 2>&1)"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
localOsVar="$(uname)"
fi
fi
@ -1497,9 +1499,9 @@ function GetOs {
localOsVar="Microsoft"
else
localOsVar="$(uname -spior 2>&1)"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
localOsVar="$(uname -v 2>&1)"
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
localOsVar="$(uname)"
fi
fi
@ -1546,7 +1548,7 @@ function GetOs {
GetOs
ENDSSH
if [ $? != 0 ]; then
if [ $? -ne 0 ]; then
Logger "Cannot connect to remote system [$REMOTE_HOST] port [$REMOTE_PORT]." "CRITICAL"
if [ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" ]; then
Logger "$(cat "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP")" "ERROR"
@ -1722,7 +1724,7 @@ function CheckConnectivityRemoteHost {
ExecTasks $! "${FUNCNAME[0]}" false 0 0 60 180 true $SLEEP_TIME $KEEP_LOGGING
#ExecTasks "${FUNCNAME[0]}" 0 0 60 180 $SLEEP_TIME $KEEP_LOGGING true true false false 1 $!
retval=$?
if [ $retval != 0 ]; then
if [ $retval -ne 0 ]; then
Logger "Cannot ping [$REMOTE_HOST]. Return code [$retval]." "WARN"
return $retval
fi
@ -1744,7 +1746,7 @@ function CheckConnectivity3rdPartyHosts {
ExecTasks $! "${FUNCNAME[0]}" false 0 0 60 180 true $SLEEP_TIME $KEEP_LOGGING
#ExecTasks "${FUNCNAME[0]}" 0 0 180 360 $SLEEP_TIME $KEEP_LOGGING true true false false 1 $!
retval=$?
if [ $retval != 0 ]; then
if [ $retval -ne 0 ]; then
Logger "Cannot ping 3rd party host [$i]. Return code [$retval]." "NOTICE"
else
remote3rdPartySuccess=true
@ -2162,7 +2164,7 @@ function GetConfFileValue () {
local value
value=$(grep "^$name=" "$file")
if [ $? == 0 ]; then
if [ $? -eq 0 ]; then
value="${value##*=}"
echo "$value"
else
@ -2595,7 +2597,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi
@ -2949,7 +2951,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi
@ -3547,7 +3549,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi
@ -4167,7 +4169,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi
@ -5107,7 +5109,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi
@ -5369,7 +5371,7 @@ function _Logger {
# Build current log file for alerts if we have a sufficient environment
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP.log"
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
fi
fi

Loading…
Cancel
Save