Reverted using eval in SendAlert
This commit is contained in:
parent
e1e6a2881c
commit
433a72938f
|
@ -7,7 +7,7 @@ PROGRAM_VERSION=1.1-dev
|
||||||
PROGRAM_BUILD=2016032901
|
PROGRAM_BUILD=2016032901
|
||||||
IS_STABLE=yes
|
IS_STABLE=yes
|
||||||
|
|
||||||
## FUNC_BUILD=2016033102
|
## FUNC_BUILD=2016033103
|
||||||
## 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
|
||||||
|
@ -208,9 +208,7 @@ function SendAlert {
|
||||||
attachment_command="-a $ALERT_LOG_FILE"
|
attachment_command="-a $ALERT_LOG_FILE"
|
||||||
fi
|
fi
|
||||||
if type mutt > /dev/null 2>&1 ; then
|
if type mutt > /dev/null 2>&1 ; then
|
||||||
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mutt) -x -s \"$subject\" $DESTINATION_MAILS $attachment_command"
|
echo "$MAIL_ALERT_MSG" | $(type -p mutt) -x -s "$subject" $DESTINATION_MAILS $attachment_command
|
||||||
Logger "Mail cmd: $cmd" "DEBUG"
|
|
||||||
eval $cmd
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert email via $(type -p mutt) !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p mutt) !!!" "WARN"
|
||||||
else
|
else
|
||||||
|
@ -223,18 +221,14 @@ function SendAlert {
|
||||||
if [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V | grep "GNU" > /dev/null; then
|
if [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V | grep "GNU" > /dev/null; then
|
||||||
attachment_command="-A $ALERT_LOG_FILE"
|
attachment_command="-A $ALERT_LOG_FILE"
|
||||||
elif [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V > /dev/null; then
|
elif [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V > /dev/null; then
|
||||||
attachment_command="-a $ALERT_LOG_FILE"
|
attachment_command="-a$ALERT_LOG_FILE"
|
||||||
else
|
else
|
||||||
attachment_command=""
|
attachment_command=""
|
||||||
fi
|
fi
|
||||||
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) $attachment_command -s \"$subject\" $DESTINATION_MAILS"
|
echo "$MAIL_ALERT_MSG" | $(type -p mail) $attachment_command -s "$subject" $DESTINATION_MAILS
|
||||||
Logger "Mail cmd: $cmd" "DEBUG"
|
|
||||||
eval $cmd
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert email via $(type -p mail) with attachments !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p mail) with attachments !!!" "WARN"
|
||||||
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) -s \"$subject\" $DESTINATION_MAILS"
|
echo "$MAIL_ALERT_MSG" | $(type -p mail) -s "$subject" $DESTINATION_MAILS
|
||||||
Logger "Mail cmd: $cmd" "DEBUG"
|
|
||||||
eval $cmd
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert email via $(type -p mail) without attachments !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p mail) without attachments !!!" "WARN"
|
||||||
else
|
else
|
||||||
|
@ -248,9 +242,7 @@ function SendAlert {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if type sendmail > /dev/null 2>&1 ; then
|
if type sendmail > /dev/null 2>&1 ; then
|
||||||
cmd="echo -e \"Subject:$subject\r\n$MAIL_ALERT_MSG\" | $(type -p sendmail) $DESTINATION_MAILS"
|
echo -e "Subject:$subject\r\n$MAIL_ALERT_MSG" | $(type -p sendmail) $DESTINATION_MAILS
|
||||||
Logger "Mail cmd: $cmd" "DEBUG"
|
|
||||||
eval $cmd
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert email via $(type -p sendmail) !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p sendmail) !!!" "WARN"
|
||||||
else
|
else
|
||||||
|
@ -276,9 +268,7 @@ function SendAlert {
|
||||||
|
|
||||||
# pfSense specific
|
# pfSense specific
|
||||||
if [ -f /usr/local/bin/mail.php ]; then
|
if [ -f /usr/local/bin/mail.php ]; then
|
||||||
cmd="echo \"$MAIL_ALERT_MSG\" | /usr/local/bin/mail.php -s=\"$subject\""
|
echo "$MAIL_ALERT_MSG" | /usr/local/bin/mail.php -s="$subject"
|
||||||
Logger "Mail cmd: $cmd" "DEBUG"
|
|
||||||
eval $cmd
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert email via /usr/local/bin/mail.php (pfsense) !!!" "WARN"
|
Logger "Cannot send alert email via /usr/local/bin/mail.php (pfsense) !!!" "WARN"
|
||||||
else
|
else
|
||||||
|
@ -288,7 +278,7 @@ function SendAlert {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If function has not returned 0 yet, assume it's critical that no alert can be sent
|
# If function has not returned 0 yet, assume it's critical that no alert can be sent
|
||||||
Logger "Cannot send alert (neither mutt, mail, sendmail, sendemail or pfSense mail.php found)." "ERROR" # Is not marked critical because execution must continue
|
Logger "Cannot send alert (neither mutt, mail, sendmail, sendemail or pfSense mail.php could be used)." "ERROR" # Is not marked critical because execution must continue
|
||||||
|
|
||||||
# Delete tmp log file
|
# Delete tmp log file
|
||||||
if [ -f "$ALERT_LOG_FILE" ]; then
|
if [ -f "$ALERT_LOG_FILE" ]; then
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
## FUNC_BUILD=2016033102
|
## FUNC_BUILD=2016033103
|
||||||
## 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
|
||||||
|
@ -199,9 +199,7 @@ function SendAlert {
|
||||||
attachment_command="-a $ALERT_LOG_FILE"
|
attachment_command="-a $ALERT_LOG_FILE"
|
||||||
fi
|
fi
|
||||||
if type mutt > /dev/null 2>&1 ; then
|
if type mutt > /dev/null 2>&1 ; then
|
||||||
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mutt) -x -s \"$subject\" $DESTINATION_MAILS $attachment_command"
|
echo "$MAIL_ALERT_MSG" | $(type -p mutt) -x -s "$subject" $DESTINATION_MAILS $attachment_command
|
||||||
Logger "Mail cmd: $cmd" "DEBUG"
|
|
||||||
eval $cmd
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert email via $(type -p mutt) !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p mutt) !!!" "WARN"
|
||||||
else
|
else
|
||||||
|
@ -214,18 +212,14 @@ function SendAlert {
|
||||||
if [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V | grep "GNU" > /dev/null; then
|
if [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V | grep "GNU" > /dev/null; then
|
||||||
attachment_command="-A $ALERT_LOG_FILE"
|
attachment_command="-A $ALERT_LOG_FILE"
|
||||||
elif [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V > /dev/null; then
|
elif [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V > /dev/null; then
|
||||||
attachment_command="-a $ALERT_LOG_FILE"
|
attachment_command="-a$ALERT_LOG_FILE"
|
||||||
else
|
else
|
||||||
attachment_command=""
|
attachment_command=""
|
||||||
fi
|
fi
|
||||||
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) $attachment_command -s \"$subject\" $DESTINATION_MAILS"
|
echo "$MAIL_ALERT_MSG" | $(type -p mail) $attachment_command -s "$subject" $DESTINATION_MAILS
|
||||||
Logger "Mail cmd: $cmd" "DEBUG"
|
|
||||||
eval $cmd
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert email via $(type -p mail) with attachments !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p mail) with attachments !!!" "WARN"
|
||||||
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) -s \"$subject\" $DESTINATION_MAILS"
|
echo "$MAIL_ALERT_MSG" | $(type -p mail) -s "$subject" $DESTINATION_MAILS
|
||||||
Logger "Mail cmd: $cmd" "DEBUG"
|
|
||||||
eval $cmd
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert email via $(type -p mail) without attachments !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p mail) without attachments !!!" "WARN"
|
||||||
else
|
else
|
||||||
|
@ -239,9 +233,7 @@ function SendAlert {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if type sendmail > /dev/null 2>&1 ; then
|
if type sendmail > /dev/null 2>&1 ; then
|
||||||
cmd="echo -e \"Subject:$subject\r\n$MAIL_ALERT_MSG\" | $(type -p sendmail) $DESTINATION_MAILS"
|
echo -e "Subject:$subject\r\n$MAIL_ALERT_MSG" | $(type -p sendmail) $DESTINATION_MAILS
|
||||||
Logger "Mail cmd: $cmd" "DEBUG"
|
|
||||||
eval $cmd
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert email via $(type -p sendmail) !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p sendmail) !!!" "WARN"
|
||||||
else
|
else
|
||||||
|
@ -267,9 +259,7 @@ function SendAlert {
|
||||||
|
|
||||||
# pfSense specific
|
# pfSense specific
|
||||||
if [ -f /usr/local/bin/mail.php ]; then
|
if [ -f /usr/local/bin/mail.php ]; then
|
||||||
cmd="echo \"$MAIL_ALERT_MSG\" | /usr/local/bin/mail.php -s=\"$subject\""
|
echo "$MAIL_ALERT_MSG" | /usr/local/bin/mail.php -s="$subject"
|
||||||
Logger "Mail cmd: $cmd" "DEBUG"
|
|
||||||
eval $cmd
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert email via /usr/local/bin/mail.php (pfsense) !!!" "WARN"
|
Logger "Cannot send alert email via /usr/local/bin/mail.php (pfsense) !!!" "WARN"
|
||||||
else
|
else
|
||||||
|
@ -279,7 +269,7 @@ function SendAlert {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If function has not returned 0 yet, assume it's critical that no alert can be sent
|
# If function has not returned 0 yet, assume it's critical that no alert can be sent
|
||||||
Logger "Cannot send alert (neither mutt, mail, sendmail, sendemail or pfSense mail.php found)." "ERROR" # Is not marked critical because execution must continue
|
Logger "Cannot send alert (neither mutt, mail, sendmail, sendemail or pfSense mail.php could be used)." "ERROR" # Is not marked critical because execution must continue
|
||||||
|
|
||||||
# Delete tmp log file
|
# Delete tmp log file
|
||||||
if [ -f "$ALERT_LOG_FILE" ]; then
|
if [ -f "$ALERT_LOG_FILE" ]; then
|
||||||
|
|
26
osync.sh
26
osync.sh
|
@ -7,7 +7,7 @@ PROGRAM_VERSION=1.1-dev
|
||||||
PROGRAM_BUILD=2016032901
|
PROGRAM_BUILD=2016032901
|
||||||
IS_STABLE=yes
|
IS_STABLE=yes
|
||||||
|
|
||||||
## FUNC_BUILD=2016033102
|
## FUNC_BUILD=2016033103
|
||||||
## 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
|
||||||
|
@ -197,9 +197,7 @@ function SendAlert {
|
||||||
attachment_command="-a $ALERT_LOG_FILE"
|
attachment_command="-a $ALERT_LOG_FILE"
|
||||||
fi
|
fi
|
||||||
if type mutt > /dev/null 2>&1 ; then
|
if type mutt > /dev/null 2>&1 ; then
|
||||||
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mutt) -x -s \"$subject\" $DESTINATION_MAILS $attachment_command"
|
echo "$MAIL_ALERT_MSG" | $(type -p mutt) -x -s "$subject" $DESTINATION_MAILS $attachment_command
|
||||||
Logger "Mail cmd: $cmd" "DEBUG"
|
|
||||||
eval $cmd
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert email via $(type -p mutt) !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p mutt) !!!" "WARN"
|
||||||
else
|
else
|
||||||
|
@ -212,18 +210,14 @@ function SendAlert {
|
||||||
if [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V | grep "GNU" > /dev/null; then
|
if [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V | grep "GNU" > /dev/null; then
|
||||||
attachment_command="-A $ALERT_LOG_FILE"
|
attachment_command="-A $ALERT_LOG_FILE"
|
||||||
elif [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V > /dev/null; then
|
elif [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V > /dev/null; then
|
||||||
attachment_command="-a $ALERT_LOG_FILE"
|
attachment_command="-a$ALERT_LOG_FILE"
|
||||||
else
|
else
|
||||||
attachment_command=""
|
attachment_command=""
|
||||||
fi
|
fi
|
||||||
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) $attachment_command -s \"$subject\" $DESTINATION_MAILS"
|
echo "$MAIL_ALERT_MSG" | $(type -p mail) $attachment_command -s "$subject" $DESTINATION_MAILS
|
||||||
Logger "Mail cmd: $cmd" "DEBUG"
|
|
||||||
eval $cmd
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert email via $(type -p mail) with attachments !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p mail) with attachments !!!" "WARN"
|
||||||
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) -s \"$subject\" $DESTINATION_MAILS"
|
echo "$MAIL_ALERT_MSG" | $(type -p mail) -s "$subject" $DESTINATION_MAILS
|
||||||
Logger "Mail cmd: $cmd" "DEBUG"
|
|
||||||
eval $cmd
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert email via $(type -p mail) without attachments !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p mail) without attachments !!!" "WARN"
|
||||||
else
|
else
|
||||||
|
@ -237,9 +231,7 @@ function SendAlert {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if type sendmail > /dev/null 2>&1 ; then
|
if type sendmail > /dev/null 2>&1 ; then
|
||||||
cmd="echo -e \"Subject:$subject\r\n$MAIL_ALERT_MSG\" | $(type -p sendmail) $DESTINATION_MAILS"
|
echo -e "Subject:$subject\r\n$MAIL_ALERT_MSG" | $(type -p sendmail) $DESTINATION_MAILS
|
||||||
Logger "Mail cmd: $cmd" "DEBUG"
|
|
||||||
eval $cmd
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert email via $(type -p sendmail) !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p sendmail) !!!" "WARN"
|
||||||
else
|
else
|
||||||
|
@ -265,9 +257,7 @@ function SendAlert {
|
||||||
|
|
||||||
# pfSense specific
|
# pfSense specific
|
||||||
if [ -f /usr/local/bin/mail.php ]; then
|
if [ -f /usr/local/bin/mail.php ]; then
|
||||||
cmd="echo \"$MAIL_ALERT_MSG\" | /usr/local/bin/mail.php -s=\"$subject\""
|
echo "$MAIL_ALERT_MSG" | /usr/local/bin/mail.php -s="$subject"
|
||||||
Logger "Mail cmd: $cmd" "DEBUG"
|
|
||||||
eval $cmd
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert email via /usr/local/bin/mail.php (pfsense) !!!" "WARN"
|
Logger "Cannot send alert email via /usr/local/bin/mail.php (pfsense) !!!" "WARN"
|
||||||
else
|
else
|
||||||
|
@ -277,7 +267,7 @@ function SendAlert {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If function has not returned 0 yet, assume it's critical that no alert can be sent
|
# If function has not returned 0 yet, assume it's critical that no alert can be sent
|
||||||
Logger "Cannot send alert (neither mutt, mail, sendmail, sendemail or pfSense mail.php found)." "ERROR" # Is not marked critical because execution must continue
|
Logger "Cannot send alert (neither mutt, mail, sendmail, sendemail or pfSense mail.php could be used)." "ERROR" # Is not marked critical because execution must continue
|
||||||
|
|
||||||
# Delete tmp log file
|
# Delete tmp log file
|
||||||
if [ -f "$ALERT_LOG_FILE" ]; then
|
if [ -f "$ALERT_LOG_FILE" ]; then
|
||||||
|
|
Loading…
Reference in New Issue