Updated scripts for sendemail

Removed scipts no longer required
Updated README.md
This commit is contained in:
Matthew McKinnon 2017-06-15 21:06:29 +10:00
parent b65dab60b6
commit 3f7512e6e9
8 changed files with 31 additions and 247 deletions

View File

@ -5,10 +5,10 @@
# Description: # Description:
# This script will email a logwatch report # This script will email a logwatch report
MAIL="support@comprofix.com" MAILTO="support@comprofix.com"
O365_SMTP=$(grep SMTP office365.conf | awk -F'=' '{print $2}') MAILFROM="support@comprofix.com"
O365_USER=$(grep USER office365.conf | awk -F'=' '{print $2}') THISSERVER=$(hostname -f)
O365_PASS=$(grep PASS office365.conf | awk -F'=' '{print $2}') SMTP="mail.comprofix.com"
#Check if removed-but-not-purged #Check if removed-but-not-purged
test -x /usr/share/logwatch/scripts/logwatch.pl || exit 0 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 #execute
/usr/sbin/logwatch > /tmp/logwatch /usr/sbin/logwatch > /tmp/logwatch
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 sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "[$THISSERVER] Logwatch" -m "$(cat /tmp/logwatch)" -q

View File

@ -35,12 +35,6 @@ This script checks for updates on your Debian based systems. If any updates are
ln -s $(pwd)/check_updates_deb_sh /etc/cron.daily ln -s $(pwd)/check_updates_deb_sh /etc/cron.daily
</code></pre> </code></pre>
#### check_updates_rpm.sh
This is the same as above but for use on rpm based distributions (CentOS, Fedora etc)
This script has been tested and used on CentOS.
#### dbbackup.sh #### dbbackup.sh
This scripts backs up mysql databases and rotates the number of backups through seven days. This scripts backs up mysql databases and rotates the number of backups through seven days.
@ -89,16 +83,6 @@ This script does an rsync from one folder location to another
ln -s ${PWD}/nasbackup.sh /etc/cron.daily ln -s ${PWD}/nasbackup.sh /etc/cron.daily
</code></pre> </code></pre>
#### rkhunter.sh
Script sends an email with the rkhunter scan and report.
<b>Installation</b>
<pre><code>
apt-get install rkhunter
ln -s ${PWD}/rkhunter.sh /etc/cron.daily
</code></pre>
#### mailQWatch.sh #### mailQWatch.sh
Script checks mailq size on a postfix system and sends an email when queue size is greater than threshold. Script checks mailq size on a postfix system and sends an email when queue size is greater than threshold.

View File

@ -15,11 +15,10 @@
# Make user configuration changes in this section # Make user configuration changes in this section
# #
MAIL="support@comprofix.com" MAILTO="support@comprofix.com"
O365_SMTP=$(grep SMTP office365.conf | awk -F'=' '{print $2}') MAILFROM="support@comprofix.com"
O365_USER=$(grep USER office365.conf | awk -F'=' '{print $2}') THISSERVER=$(hostname -f)
O365_PASS=$(grep PASS office365.conf | awk -F'=' '{print $2}') SMTP="mail.comprofix.com"
AUTOUPDATE="no" AUTOUPDATE="no"
LOGFILE="/var/log/server_maint.log" LOGFILE="/var/log/server_maint.log"
@ -64,7 +63,9 @@ check_return() {
} }
send_error_email() { send_error_email() {
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, sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "[$THISSERVER] There was an error whilst running $0" -m "
Hello,
Whilst running the update script ($0) on $THISSERVER there was a problem. Whilst running the update script ($0) on $THISSERVER there was a problem.
@ -116,7 +117,7 @@ See the logfile for more info: vim $LOGFILE
Regards. " >/tmp/servermail.msg 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)" -q sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -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 echo "$(date) [MESSAGE] Packages need updating email sent to $MAILTO" >> $LOGFILE

View File

@ -1,141 +0,0 @@
#!/bin/bash
# Script Name: check_updates_rpm
# Author Name: Matt McKinnon
# Date: 7th June 2016
# Description: For use on rpm based distros ie CentOS, Red Hat, Fedora
# This script will:
# Clean up the local rpm repository of retrieved packages (yum clean)
# Resync the package index (yum makecache)
# If called with AUTOUPDATE set to yes then SECURITY updates will be downloaded and applied. (The package yum-plugin-security is required Install using
# yum install yum-plugin-security)
#
# Make user configuration changes in this section
#
MAILTO="support@comprofix.com"
AUTOUPDATE="no"
LOGFILE="/var/log/server_maint.log"
THISSERVER=$(hostname -f)
#
# End of user configuration section
#
DASHES="---------------------------------------------------------------------------------"
DASHES2="================================================================================="
# Check if the script is being run as root exit if it is not.
if [ $(id -u) -ne 0 ]
then
echo "ur not root bro"
exit 1
fi
startlogging() {
echo $DASHES2 >> $LOGFILE
echo "$0 started running at `date`" >> $LOGFILE
echo $DASHES2 >> $LOGFILE
}
stoplogging() {
echo "`date` [MESSAGE] $0 finished runnning" >> $LOGFILE
echo $DASHES >> $LOGFILE
}
check_return() {
if [ "$?" -ne "0" ]
then
echo "$(date) [ERROR] $1 failed to run" >> $LOGFILE
send_error_email $1
stoplogging
exit 1
fi
echo "$(date) [SUCCESS] $1 ran without error" >> $LOGFILE
}
send_error_email() {
echo "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@${IPADDR[0]}) and check the log file:
vim $LOGFILE
Regards." | /bin/mail -s "[$THISSERVER] There was an error whilst running $0" $MAILTO
}
# 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
yum clean all > /dev/null
check_return "yum clean all"
yum makecache > /dev/null
check_return "yum makecache"
if [[ "$AUTOUPDATE" == "yes" ]]
then
yum -y update --security > /dev/null
check_return "yum -y update --security"
else
PACKAGES_TO_BE_UPGRADED=`yum list updates -q`
check_return "yum list updates -q"
fi
if [[ -z $PACKAGES_TO_BE_UPGRADED ]]
then
echo "$(date) [MESSAGE] No packages need updating." >> $LOGFILE
else
echo "
Hello,
Packages requiring updates 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@${IPADDR[0]}) and run the following command:
yum upgrade
See the logfile for more info: vim $LOGFILE
Regards. " | /bin/mail -s "[$THISSERVER] server may need some updates applied" $MAILTO
echo "`date` [MESSAGE] Packages need updating email sent to $MAILTO" >> $LOGFILE
fi
stoplogging
exit 0

View File

@ -16,9 +16,10 @@
MAIL="support@comprofix.com" MAIL="support@comprofix.com"
O365_SMTP=$(grep SMTP office365.conf | awk -F'=' '{print $2}') MAILTO="support@comprofix.com"
O365_USER=$(grep USER office365.conf | awk -F'=' '{print $2}') MAILFROM="support@comprofix.com"
O365_PASS=$(grep PASS office365.conf | awk -F'=' '{print $2}') THISSERVER=$(hostname -f)
SMTP="mail.comprofix.com"
SUBJECT="$(hostname -f) Database Backup Completed $BAKDATE" SUBJECT="$(hostname -f) Database Backup Completed $BAKDATE"
BAKDATE=$(date +%Y%m%d) BAKDATE=$(date +%Y%m%d)
@ -43,7 +44,7 @@ for db in $databases; do
done done
sendemail -o tls=auto -s "$O365_SMTP" -xu "$O365_USER" -xp "$O365_PASS" -t "$MAIL" -f "$MAIL" -u "$SUBJECT" -m "$(cat /tmp/dbbackup.msg)" sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "$SUBJECT" -m "$(cat /tmp/dbbackup.msg)" -q
#Use Below to use systems postfix or local MTA #Use Below to use systems postfix or local MTA
#cat /tmp/dbbackup.msg | mail -s "$SUBJECT" "$MAIL" #cat /tmp/dbbackup.msg | mail -s "$SUBJECT" "$MAIL"

View File

@ -5,10 +5,10 @@
# Description: # Description:
# This script will email when diskspace is high. # This script will email when diskspace is high.
MAIL="support@comprofix.com" MAILTO="support@comprofix.com"
O365_SMTP=$(grep SMTP office365.conf | awk -F'=' '{print $2}') MAILFROM="support@comprofix.com"
O365_USER=$(grep USER office365.conf | awk -F'=' '{print $2}') THISSERVER=$(hostname -f)
O365_PASS=$(grep PASS office365.conf | awk -F'=' '{print $2}') SMTP="mail.comprofix.com"
LOGFILE="/var/log/diskalert.log" LOGFILE="/var/log/diskalert.log"
THISSERVER=$(hostname -f) THISSERVER=$(hostname -f)
@ -62,7 +62,8 @@ See the logfile for more info: vim $LOGFILE
Regards, " >/tmp/diskalertmail.msg Regards, " >/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 sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -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 echo "$(date) [MESSAGE] Running out of disk space email sent to $MAILTO" >> $LOGFILE
fi fi

View File

@ -1,15 +1,12 @@
#!/bin/bash #!/bin/bash
#apps backup downloads fun games movies mp3s tvshows wow
#MAILTO=mmckinnon@comprofix.com
#SMTP=mail.comprofix.com
MAIL="support@comprofix.com" MAILTO="support@comprofix.com"
O365_SMTP=$(grep SMTP office365.conf | awk -F'=' '{print $2}') MAILFROM="support@comprofix.com"
O365_USER=$(grep USER office365.conf | awk -F'=' '{print $2}') THISSERVER=$(hostname -f)
O365_PASS=$(grep PASS office365.conf | awk -F'=' '{print $2}') SMTP="mail.comprofix.com"
#MAILFROM="$(hostname)@$(dnsdomainname)"
SUBJECT="Backup Log `date +%d-%m-%Y`" SUBJECT="Backup Log `date +%d-%m-%Y`"
LOGFOLDER=/var/log/nasbackup LOGFOLDER=/var/log/nasbackup
LOGFILE=$LOGFOLDER/backuplog-`date +%d-%m-%Y.log` LOGFILE=$LOGFOLDER/backuplog-`date +%d-%m-%Y.log`
@ -50,5 +47,5 @@ echo "$(date) [MESSAGE] Backup completed $LOGFILE has been emailed." >> $LOGFILE
stoplogging stoplogging
#sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "$SUBJECT" -m "$(cat $LOGFILE)"
sendemail -o tls=auto -s "$O365_SMTP" -xu "$O365_USER" -xp "$O365_PASS" -t "$MAIL" -f "$MAIL" -u "$SUBJECT" -a "$LOGFILE" -m "$SUBJECT" sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "$SUBJECT" -a "$LOGFILE" -m "$SUBJECT"

View File

@ -1,59 +0,0 @@
#!/bin/bash
#
# Shorewall blacklist file
# blacklist file
#
BLACKLIST="/etc/shorewall/blacklist"
CUSTOM="/etc/shorewall/custom-blacklist"
#
# get URL
#
URL[0]="http://feeds.dshield.org/block.txt"
URL[1]="http://www.spamhaus.org/drop/drop.lasso"
#Counrtry BlockLists
COUNTRY=(cn tw tr mx il id ua za)
IPDENY="http://www.ipdeny.com/ipblocks/data/countries"
#
# Don't Edit After this line
#
# Temporary dump staging folder
TMP=$(mktemp -d -t tmp.XXXXXXXXXX)
#
# @method to delete Temporary folder
#
function finish {
rm -rf "$TMP"
}
trap finish EXIT
echo "Downloading new blacklists...."
#Blank out existing blacklists
cat /dev/null > "$TMP/blacklist"
cat /dev/null > $BLACKLIST
#Add custom entries
if [[ -s $CUSTOM ]]; then
cat $CUSTOM >> "$TMP/blacklist"
fi
## top 20 attacking class C (/24)
wget -q -O - ${URL[0]} | sed '1,/Start/d' | sed '/#/d' | awk '{print $1,$3}' | sed 's/ /\//' >> "$TMP/blacklist"
## Spamhaus DROP List
wget -q -O - ${URL[1]} | sed '1,/Expires/d' | awk '{print $1}' >> "$TMP/blacklist"
## Country Blocklists
for BLOCK in ${COUNTRY[*]}; do
wget -q -O - $IPDENY/$BLOCK.zone | awk '{print $1}' >> "$TMP/blacklist"
done
#Remove duplicate entries
sort "$TMP/blacklist" | uniq -c | awk '{print $2}' > $BLACKLIST
shorewall refresh