Updated Scripts to send emails via Office 365 SMTP
This commit is contained in:
parent
fd02560118
commit
b65dab60b6
10
00logwatch
10
00logwatch
@ -5,10 +5,10 @@
|
||||
# Description:
|
||||
# This script will email a logwatch report
|
||||
|
||||
MAILTO="support@comprofix.com"
|
||||
SMTP=mail.comprofix.com
|
||||
THISSERVER=$(hostname -f)
|
||||
MAILFROM="$(hostname)@$(dnsdomainname)"
|
||||
MAIL="support@comprofix.com"
|
||||
O365_SMTP=$(grep SMTP office365.conf | awk -F'=' '{print $2}')
|
||||
O365_USER=$(grep USER office365.conf | awk -F'=' '{print $2}')
|
||||
O365_PASS=$(grep PASS office365.conf | awk -F'=' '{print $2}')
|
||||
|
||||
#Check if removed-but-not-purged
|
||||
test -x /usr/share/logwatch/scripts/logwatch.pl || exit 0
|
||||
@ -16,4 +16,4 @@ test -x /usr/share/logwatch/scripts/logwatch.pl || exit 0
|
||||
#execute
|
||||
/usr/sbin/logwatch > /tmp/logwatch
|
||||
|
||||
sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "[$THISSERVER] Logwatch" -m "$(cat /tmp/logwatch)" -q
|
||||
sendemail -o tls=auto -s "$O365_SMTP" -xu "$O365_USER" -xp "$O365_PASS" -t "$MAIL" -f "$MAIL" -u "[$THISSERVER] Logwatch" -m "$(cat /tmp/logwatch)" -q
|
||||
|
@ -64,46 +64,20 @@ check_return() {
|
||||
}
|
||||
|
||||
send_error_email() {
|
||||
sendemail -f "$THISSERVER <$MAILFROM>" -t $MAILTO -u "[$THISSERVER] There was an error whilst running $0" -s $SMTP
|
||||
|
||||
"Hello,
|
||||
sendemail -o tls=auto -s "$O365_SMTP" -xu "$O365_USER" -xp "$O365_PASS" -t "$MAIL" -f "$MAIL" -u "[$THISSERVER] There was an error whilst running $0" -m "Hello,
|
||||
|
||||
Whilst running the update script ($0) on $THISSERVER there was a problem.
|
||||
|
||||
[ERROR] "$1" failed to run
|
||||
|
||||
The server has the following network interfaces configured ${SERVERADDS[@]}.
|
||||
|
||||
Please log in via ssh (e.g. ssh root@$(hostname -f)) and check the log file:
|
||||
|
||||
vim $LOGFILE
|
||||
|
||||
Regards."
|
||||
Regards." -q
|
||||
|
||||
}
|
||||
|
||||
# IP Address stuff
|
||||
declare -a IPADDR
|
||||
declare -a NICINTERFACE
|
||||
declare -a SERVERADDS
|
||||
index=0
|
||||
|
||||
for i in $( ifconfig | grep 'inet addr' | awk '{print $2}'| sed 's#addr:##g' );
|
||||
do
|
||||
IPADDR[$index]=$i
|
||||
let "index += 1"
|
||||
done
|
||||
|
||||
index=0
|
||||
|
||||
for i in $( ifconfig | grep 'eth' | awk '{print $1}' );
|
||||
do
|
||||
SERVERADDS[$index]="$i ${IPADDR[$index]}"
|
||||
let "index += 1"
|
||||
done
|
||||
|
||||
# End IP Address stuff
|
||||
|
||||
|
||||
startlogging
|
||||
|
||||
apt-get clean > /dev/null
|
||||
@ -134,8 +108,6 @@ Packages have been downloaded onto $THISSERVER.
|
||||
|
||||
$PACKAGES_TO_BE_UPGRADED
|
||||
|
||||
The server has the following network interfaces configured ${SERVERADDS[@]}.
|
||||
|
||||
To update the server log in via ssh (e.g. ssh root@$(hostname -f)) and run the following command:
|
||||
|
||||
apt-get upgrade
|
||||
@ -144,7 +116,7 @@ See the logfile for more info: vim $LOGFILE
|
||||
|
||||
Regards. " >/tmp/servermail.msg
|
||||
|
||||
sendemail -o tls=auto -s "$O365_SMTP" -xu "$O365_USER" -xp "$O365_PASS" -t "$MAIL" -f "$MAIL" -u "[$THISSERVER] server may need some updates applied" -m "$(cat /tmp/servermail.msg)"
|
||||
sendemail -o tls=auto -s "$O365_SMTP" -xu "$O365_USER" -xp "$O365_PASS" -t "$MAIL" -f "$MAIL" -u "[$THISSERVER] server may need some updates applied" -m "$(cat /tmp/servermail.msg)" -q
|
||||
|
||||
|
||||
echo "$(date) [MESSAGE] Packages need updating email sent to $MAILTO" >> $LOGFILE
|
||||
|
14
dbbackup.sh
14
dbbackup.sh
@ -12,10 +12,15 @@
|
||||
# Login to mysql with your root user.
|
||||
#
|
||||
# CREATE USER 'dbbackup'@'localhost' IDENTIFIED BY 'PASSWORD';
|
||||
# GRANT LOCK TABLES, SELECT, SHOW VIEW, RELOAD, REPLICATION CLIENT, EVENT, TRIGGER ON *.* TO 'backup'@'localhost';
|
||||
# GRANT LOCK TABLES, SELECT, SHOW VIEW, RELOAD, REPLICATION CLIENT, EVENT, TRIGGER ON *.* TO 'dbbackup'@'localhost';
|
||||
|
||||
|
||||
MAIL="support@comprofix.com"
|
||||
O365_SMTP=$(grep SMTP office365.conf | awk -F'=' '{print $2}')
|
||||
O365_USER=$(grep USER office365.conf | awk -F'=' '{print $2}')
|
||||
O365_PASS=$(grep PASS office365.conf | awk -F'=' '{print $2}')
|
||||
|
||||
SUBJECT="$(hostname -f) Database Backup Completed $BAKDATE"
|
||||
MAILTO="support@comprofix.com"
|
||||
BAKDATE=$(date +%Y%m%d)
|
||||
DBUSER='dbbackup'
|
||||
DBPASS='EWFfP3GZsqr427Yj'
|
||||
@ -38,5 +43,8 @@ for db in $databases; do
|
||||
|
||||
done
|
||||
|
||||
cat /tmp/dbbackup.msg | mail -r "$MAILTO" -s "$SUBJECT" "$MAILTO"
|
||||
sendemail -o tls=auto -s "$O365_SMTP" -xu "$O365_USER" -xp "$O365_PASS" -t "$MAIL" -f "$MAIL" -u "$SUBJECT" -m "$(cat /tmp/dbbackup.msg)"
|
||||
|
||||
#Use Below to use systems postfix or local MTA
|
||||
#cat /tmp/dbbackup.msg | mail -s "$SUBJECT" "$MAIL"
|
||||
rm -fr /tmp/dbbackup.msg
|
||||
|
11
diskalert.sh
11
diskalert.sh
@ -5,11 +5,14 @@
|
||||
# Description:
|
||||
# This script will email when diskspace is high.
|
||||
|
||||
MAILTO="support@comprofix.com"
|
||||
SMTP=mail.comprofix.com
|
||||
MAIL="support@comprofix.com"
|
||||
O365_SMTP=$(grep SMTP office365.conf | awk -F'=' '{print $2}')
|
||||
O365_USER=$(grep USER office365.conf | awk -F'=' '{print $2}')
|
||||
O365_PASS=$(grep PASS office365.conf | awk -F'=' '{print $2}')
|
||||
|
||||
LOGFILE="/var/log/diskalert.log"
|
||||
THISSERVER=$(hostname -f)
|
||||
MAILFROM="$(hostname)@$(dnsdomainname)"
|
||||
|
||||
|
||||
startlogging() {
|
||||
echo $DASHES2 >> $LOGFILE
|
||||
@ -59,7 +62,7 @@ See the logfile for more info: vim $LOGFILE
|
||||
|
||||
Regards, " >/tmp/diskalertmail.msg
|
||||
|
||||
sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "[$THISSERVER] is running out of disk space" -m "$(cat /tmp/diskalertmail.msg)"
|
||||
sendemail -o tls=auto -s "$O365_SMTP" -xu "$O365_USER" -xp "$O365_PASS" -t "$MAIL" -f "$MAIL" -u "[$THISSERVER] is running out of disk space" -m "$(cat /tmp/diskalertmail.msg)" -q
|
||||
echo "$(date) [MESSAGE] Running out of disk space email sent to $MAILTO" >> $LOGFILE
|
||||
|
||||
fi
|
||||
|
@ -1,31 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Script Name: sentora_www-backup.sh
|
||||
# Author Name: Matt McKinnon
|
||||
# Date: 7th June 2016
|
||||
# Description:
|
||||
# This script will:
|
||||
# Backup your public_html folder under /var/sentora/hostdata/DOMAIN_NAME/public_html
|
||||
|
||||
BACKUPDIR='/BACKUP/www/'
|
||||
BAKDATE=$(date +%Y%m%d)
|
||||
HOSTDATA="/var/sentora/hostdata"
|
||||
MAILTO="support@comprofix.com"
|
||||
SUBJECT="$(hostname -f) sentora sites backup"
|
||||
|
||||
rotate_backups() {
|
||||
find $BACKUPDIR -type f -mtime +7 -exec rm -frv {} \;
|
||||
|
||||
}
|
||||
|
||||
rotate_backups
|
||||
|
||||
WEBPATH=$(find $HOSTDATA/* -maxdepth 0 -type d | awk -F/ '{print $5}')
|
||||
|
||||
for SITES in $WEBPATH; do
|
||||
tar -zcf $BACKUPDIR/$SITES-$BAKDATE.tar.gz -P $HOSTDATA/$SITES >> /tmp/sentora_backup.msg
|
||||
echo "$SITES-$BAKDATE.tar.gz - $SITES backup successfull" >> /tmp/sentora_backup.msg
|
||||
done
|
||||
|
||||
cat /tmp/sentora_backup.msg | mail -r "$MAILTO" -s "$SUBJECT" "$MAILTO"
|
||||
rm -fr /tmp/sentora_backup.msg
|
||||
|
Loading…
Reference in New Issue
Block a user