mirror of
https://github.com/deajan/obackup.git
synced 2026-02-06 07:05:14 +01:00
Improved mail sending
This commit is contained in:
@@ -5,10 +5,10 @@ PROGRAM="obackup"
|
|||||||
AUTHOR="(L) 2013-2016 by Orsiris de Jong"
|
AUTHOR="(L) 2013-2016 by Orsiris de Jong"
|
||||||
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
||||||
PROGRAM_VERSION=2.0-pre
|
PROGRAM_VERSION=2.0-pre
|
||||||
PROGRAM_BUILD=2016030301
|
PROGRAM_BUILD=2016030302
|
||||||
IS_STABLE=no
|
IS_STABLE=no
|
||||||
|
|
||||||
## FUNC_BUILD=2016030302
|
## FUNC_BUILD=2016030303
|
||||||
## 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
|
||||||
@@ -281,9 +281,10 @@ 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
|
||||||
echo "$MAIL_ALERT_MSG" | $(type -p mutt) -x -s "$subject" $DESTINATION_MAILS $attachment_command
|
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mutt) -x -s \"$subject\" $DESTINATION_MAILS $attachment_command"
|
||||||
|
eval $cmd
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "WARNING: Cannot send alert email via $(type -p mutt) !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p mutt) !!!" "WARN"
|
||||||
else
|
else
|
||||||
Logger "Sent alert mail using mutt." "NOTICE"
|
Logger "Sent alert mail using mutt." "NOTICE"
|
||||||
return 0
|
return 0
|
||||||
@@ -298,12 +299,14 @@ function SendAlert {
|
|||||||
else
|
else
|
||||||
attachment_command=""
|
attachment_command=""
|
||||||
fi
|
fi
|
||||||
echo "$MAIL_ALERT_MSG" | $(type -p mail) $attachment_command -s "$subject" $DESTINATION_MAILS
|
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) $attachment_command -s \"$subject\" $DESTINATION_MAILS"
|
||||||
|
eval $cmd
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "WARNING: Cannot send alert email via $(type -p mail) with attachments !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p mail) with attachments !!!" "WARN"
|
||||||
echo "$MAIL_ALERT_MSG" | $(type -p mail) -s "$subject" $DESTINATION_MAILS
|
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) -s \"$subject\" $DESTINATION_MAILS"
|
||||||
|
eval $cmd
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "WARNING: 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
|
||||||
Logger "Sent alert mail using mail command without attachment." "NOTICE"
|
Logger "Sent alert mail using mail command without attachment." "NOTICE"
|
||||||
return 0
|
return 0
|
||||||
@@ -315,9 +318,10 @@ function SendAlert {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if type sendmail > /dev/null 2>&1 ; then
|
if type sendmail > /dev/null 2>&1 ; then
|
||||||
echo -e "Subject:$subject\r\n$MAIL_ALERT_MSG" | $(type -p sendmail) $DESTINATION_MAILS
|
cmd="echo -e \"Subject:$subject\r\n$MAIL_ALERT_MSG\" | $(type -p sendmail) $DESTINATION_MAILS"
|
||||||
|
eval $cmd
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "WARNING: Cannot send alert email via $(type -p sendmail) !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p sendmail) !!!" "WARN"
|
||||||
else
|
else
|
||||||
Logger "Sent alert mail using sendmail command without attachment." "NOTICE"
|
Logger "Sent alert mail using sendmail command without attachment." "NOTICE"
|
||||||
return 0
|
return 0
|
||||||
@@ -332,7 +336,7 @@ function SendAlert {
|
|||||||
fi
|
fi
|
||||||
$(type -p sendemail) -f $SENDER_MAIL -t $DESTINATION_MAILS -u "$subject" -m "$MAIL_ALERT_MSG" -s $SMTP_SERVER $SMTP_OPTIONS > /dev/null 2>&1
|
$(type -p sendemail) -f $SENDER_MAIL -t $DESTINATION_MAILS -u "$subject" -m "$MAIL_ALERT_MSG" -s $SMTP_SERVER $SMTP_OPTIONS > /dev/null 2>&1
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "WARNING: Cannot send alert email via $(type -p sendemail) !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p sendemail) !!!" "WARN"
|
||||||
else
|
else
|
||||||
Logger "Sent alert mail using sendemail command without attachment." "NOTICE"
|
Logger "Sent alert mail using sendemail command without attachment." "NOTICE"
|
||||||
return 0
|
return 0
|
||||||
@@ -340,7 +344,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 "/!\ CRITICAL: Cannot send alert (neither mutt, mail, sendmail nor sendemail found)." "ERROR" # Is not marked critical because execution must continue
|
Logger "Cannot send alert (neither mutt, mail, sendmail nor sendemail found)." "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
|
||||||
@@ -996,7 +1000,7 @@ CAN_BACKUP_SQL=1
|
|||||||
CAN_BACKUP_FILES=1
|
CAN_BACKUP_FILES=1
|
||||||
|
|
||||||
function TrapStop {
|
function TrapStop {
|
||||||
Logger " /!\ WARNING: Manual exit of backup script. Backups may be in inconsistent state." "WARN"
|
Logger "/!\ Manual exit of backup script. Backups may be in inconsistent state." "WARN"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ PROGRAM="obackup"
|
|||||||
AUTHOR="(L) 2013-2016 by Orsiris de Jong"
|
AUTHOR="(L) 2013-2016 by Orsiris de Jong"
|
||||||
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
||||||
PROGRAM_VERSION=2.0-pre
|
PROGRAM_VERSION=2.0-pre
|
||||||
PROGRAM_BUILD=2016030301
|
PROGRAM_BUILD=2016030302
|
||||||
IS_STABLE=no
|
IS_STABLE=no
|
||||||
|
|
||||||
source "./ofunctions.sh"
|
source "./ofunctions.sh"
|
||||||
@@ -27,7 +27,7 @@ CAN_BACKUP_SQL=1
|
|||||||
CAN_BACKUP_FILES=1
|
CAN_BACKUP_FILES=1
|
||||||
|
|
||||||
function TrapStop {
|
function TrapStop {
|
||||||
Logger " /!\ WARNING: Manual exit of backup script. Backups may be in inconsistent state." "WARN"
|
Logger "/!\ Manual exit of backup script. Backups may be in inconsistent state." "WARN"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
## FUNC_BUILD=2016030302
|
## FUNC_BUILD=2016030303
|
||||||
## 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
|
||||||
@@ -271,9 +271,10 @@ 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
|
||||||
echo "$MAIL_ALERT_MSG" | $(type -p mutt) -x -s "$subject" $DESTINATION_MAILS $attachment_command
|
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mutt) -x -s \"$subject\" $DESTINATION_MAILS $attachment_command"
|
||||||
|
eval $cmd
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "WARNING: Cannot send alert email via $(type -p mutt) !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p mutt) !!!" "WARN"
|
||||||
else
|
else
|
||||||
Logger "Sent alert mail using mutt." "NOTICE"
|
Logger "Sent alert mail using mutt." "NOTICE"
|
||||||
return 0
|
return 0
|
||||||
@@ -288,12 +289,14 @@ function SendAlert {
|
|||||||
else
|
else
|
||||||
attachment_command=""
|
attachment_command=""
|
||||||
fi
|
fi
|
||||||
echo "$MAIL_ALERT_MSG" | $(type -p mail) $attachment_command -s "$subject" $DESTINATION_MAILS
|
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) $attachment_command -s \"$subject\" $DESTINATION_MAILS"
|
||||||
|
eval $cmd
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "WARNING: Cannot send alert email via $(type -p mail) with attachments !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p mail) with attachments !!!" "WARN"
|
||||||
echo "$MAIL_ALERT_MSG" | $(type -p mail) -s "$subject" $DESTINATION_MAILS
|
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) -s \"$subject\" $DESTINATION_MAILS"
|
||||||
|
eval $cmd
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "WARNING: 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
|
||||||
Logger "Sent alert mail using mail command without attachment." "NOTICE"
|
Logger "Sent alert mail using mail command without attachment." "NOTICE"
|
||||||
return 0
|
return 0
|
||||||
@@ -305,9 +308,10 @@ function SendAlert {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if type sendmail > /dev/null 2>&1 ; then
|
if type sendmail > /dev/null 2>&1 ; then
|
||||||
echo -e "Subject:$subject\r\n$MAIL_ALERT_MSG" | $(type -p sendmail) $DESTINATION_MAILS
|
cmd="echo -e \"Subject:$subject\r\n$MAIL_ALERT_MSG\" | $(type -p sendmail) $DESTINATION_MAILS"
|
||||||
|
eval $cmd
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "WARNING: Cannot send alert email via $(type -p sendmail) !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p sendmail) !!!" "WARN"
|
||||||
else
|
else
|
||||||
Logger "Sent alert mail using sendmail command without attachment." "NOTICE"
|
Logger "Sent alert mail using sendmail command without attachment." "NOTICE"
|
||||||
return 0
|
return 0
|
||||||
@@ -322,7 +326,7 @@ function SendAlert {
|
|||||||
fi
|
fi
|
||||||
$(type -p sendemail) -f $SENDER_MAIL -t $DESTINATION_MAILS -u "$subject" -m "$MAIL_ALERT_MSG" -s $SMTP_SERVER $SMTP_OPTIONS > /dev/null 2>&1
|
$(type -p sendemail) -f $SENDER_MAIL -t $DESTINATION_MAILS -u "$subject" -m "$MAIL_ALERT_MSG" -s $SMTP_SERVER $SMTP_OPTIONS > /dev/null 2>&1
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "WARNING: Cannot send alert email via $(type -p sendemail) !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p sendemail) !!!" "WARN"
|
||||||
else
|
else
|
||||||
Logger "Sent alert mail using sendemail command without attachment." "NOTICE"
|
Logger "Sent alert mail using sendemail command without attachment." "NOTICE"
|
||||||
return 0
|
return 0
|
||||||
@@ -330,7 +334,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 "/!\ CRITICAL: Cannot send alert (neither mutt, mail, sendmail nor sendemail found)." "ERROR" # Is not marked critical because execution must continue
|
Logger "Cannot send alert (neither mutt, mail, sendmail nor sendemail found)." "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
|
||||||
|
|||||||
30
obackup.sh
30
obackup.sh
@@ -5,10 +5,10 @@ PROGRAM="obackup"
|
|||||||
AUTHOR="(L) 2013-2016 by Orsiris de Jong"
|
AUTHOR="(L) 2013-2016 by Orsiris de Jong"
|
||||||
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
||||||
PROGRAM_VERSION=2.0-pre
|
PROGRAM_VERSION=2.0-pre
|
||||||
PROGRAM_BUILD=2016030301
|
PROGRAM_BUILD=2016030302
|
||||||
IS_STABLE=no
|
IS_STABLE=no
|
||||||
|
|
||||||
## FUNC_BUILD=2016030302
|
## FUNC_BUILD=2016030303
|
||||||
## 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
|
||||||
@@ -269,9 +269,10 @@ 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
|
||||||
echo "$MAIL_ALERT_MSG" | $(type -p mutt) -x -s "$subject" $DESTINATION_MAILS $attachment_command
|
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mutt) -x -s \"$subject\" $DESTINATION_MAILS $attachment_command"
|
||||||
|
eval $cmd
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "WARNING: Cannot send alert email via $(type -p mutt) !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p mutt) !!!" "WARN"
|
||||||
else
|
else
|
||||||
Logger "Sent alert mail using mutt." "NOTICE"
|
Logger "Sent alert mail using mutt." "NOTICE"
|
||||||
return 0
|
return 0
|
||||||
@@ -286,12 +287,14 @@ function SendAlert {
|
|||||||
else
|
else
|
||||||
attachment_command=""
|
attachment_command=""
|
||||||
fi
|
fi
|
||||||
echo "$MAIL_ALERT_MSG" | $(type -p mail) $attachment_command -s "$subject" $DESTINATION_MAILS
|
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) $attachment_command -s \"$subject\" $DESTINATION_MAILS"
|
||||||
|
eval $cmd
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "WARNING: Cannot send alert email via $(type -p mail) with attachments !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p mail) with attachments !!!" "WARN"
|
||||||
echo "$MAIL_ALERT_MSG" | $(type -p mail) -s "$subject" $DESTINATION_MAILS
|
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) -s \"$subject\" $DESTINATION_MAILS"
|
||||||
|
eval $cmd
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "WARNING: 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
|
||||||
Logger "Sent alert mail using mail command without attachment." "NOTICE"
|
Logger "Sent alert mail using mail command without attachment." "NOTICE"
|
||||||
return 0
|
return 0
|
||||||
@@ -303,9 +306,10 @@ function SendAlert {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if type sendmail > /dev/null 2>&1 ; then
|
if type sendmail > /dev/null 2>&1 ; then
|
||||||
echo -e "Subject:$subject\r\n$MAIL_ALERT_MSG" | $(type -p sendmail) $DESTINATION_MAILS
|
cmd="echo -e \"Subject:$subject\r\n$MAIL_ALERT_MSG\" | $(type -p sendmail) $DESTINATION_MAILS"
|
||||||
|
eval $cmd
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "WARNING: Cannot send alert email via $(type -p sendmail) !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p sendmail) !!!" "WARN"
|
||||||
else
|
else
|
||||||
Logger "Sent alert mail using sendmail command without attachment." "NOTICE"
|
Logger "Sent alert mail using sendmail command without attachment." "NOTICE"
|
||||||
return 0
|
return 0
|
||||||
@@ -320,7 +324,7 @@ function SendAlert {
|
|||||||
fi
|
fi
|
||||||
$(type -p sendemail) -f $SENDER_MAIL -t $DESTINATION_MAILS -u "$subject" -m "$MAIL_ALERT_MSG" -s $SMTP_SERVER $SMTP_OPTIONS > /dev/null 2>&1
|
$(type -p sendemail) -f $SENDER_MAIL -t $DESTINATION_MAILS -u "$subject" -m "$MAIL_ALERT_MSG" -s $SMTP_SERVER $SMTP_OPTIONS > /dev/null 2>&1
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "WARNING: Cannot send alert email via $(type -p sendemail) !!!" "WARN"
|
Logger "Cannot send alert email via $(type -p sendemail) !!!" "WARN"
|
||||||
else
|
else
|
||||||
Logger "Sent alert mail using sendemail command without attachment." "NOTICE"
|
Logger "Sent alert mail using sendemail command without attachment." "NOTICE"
|
||||||
return 0
|
return 0
|
||||||
@@ -328,7 +332,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 "/!\ CRITICAL: Cannot send alert (neither mutt, mail, sendmail nor sendemail found)." "ERROR" # Is not marked critical because execution must continue
|
Logger "Cannot send alert (neither mutt, mail, sendmail nor sendemail found)." "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
|
||||||
@@ -924,7 +928,7 @@ CAN_BACKUP_SQL=1
|
|||||||
CAN_BACKUP_FILES=1
|
CAN_BACKUP_FILES=1
|
||||||
|
|
||||||
function TrapStop {
|
function TrapStop {
|
||||||
Logger " /!\ WARNING: Manual exit of backup script. Backups may be in inconsistent state." "WARN"
|
Logger "/!\ Manual exit of backup script. Backups may be in inconsistent state." "WARN"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user