From 3f7512e6e959ff835baafc12822782d711a4ab7d Mon Sep 17 00:00:00 2001 From: Matthew McKinnon Date: Thu, 15 Jun 2017 21:06:29 +1000 Subject: [PATCH] Updated scripts for sendemail Removed scipts no longer required Updated README.md --- 00logwatch | 10 +-- README.md | 16 ----- check_updates_deb.sh | 15 +++-- check_updates_rpm.sh | 141 ----------------------------------------- dbbackup.sh | 9 +-- diskalert.sh | 11 ++-- nasbackup.sh | 17 ++--- shorewall-blacklist.sh | 59 ----------------- 8 files changed, 31 insertions(+), 247 deletions(-) delete mode 100755 check_updates_rpm.sh delete mode 100755 shorewall-blacklist.sh diff --git a/00logwatch b/00logwatch index 68b2ee0..628bc09 100755 --- a/00logwatch +++ b/00logwatch @@ -5,10 +5,10 @@ # Description: # This script will email a logwatch report -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}') +MAILTO="support@comprofix.com" +MAILFROM="support@comprofix.com" +THISSERVER=$(hostname -f) +SMTP="mail.comprofix.com" #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=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 diff --git a/README.md b/README.md index 8a9504a..608dbf0 100755 --- a/README.md +++ b/README.md @@ -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 -#### 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 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 -#### rkhunter.sh - -Script sends an email with the rkhunter scan and report. - -Installation -

-apt-get install rkhunter
-ln -s ${PWD}/rkhunter.sh /etc/cron.daily
-
- #### mailQWatch.sh Script checks mailq size on a postfix system and sends an email when queue size is greater than threshold. diff --git a/check_updates_deb.sh b/check_updates_deb.sh index f64a781..b7b6f13 100755 --- a/check_updates_deb.sh +++ b/check_updates_deb.sh @@ -15,11 +15,10 @@ # Make user configuration changes in this section # -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}') - +MAILTO="support@comprofix.com" +MAILFROM="support@comprofix.com" +THISSERVER=$(hostname -f) +SMTP="mail.comprofix.com" AUTOUPDATE="no" LOGFILE="/var/log/server_maint.log" @@ -64,7 +63,9 @@ check_return() { } 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. @@ -116,7 +117,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)" -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 diff --git a/check_updates_rpm.sh b/check_updates_rpm.sh deleted file mode 100755 index 37c6df1..0000000 --- a/check_updates_rpm.sh +++ /dev/null @@ -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 diff --git a/dbbackup.sh b/dbbackup.sh index 5b14f7d..90f609e 100755 --- a/dbbackup.sh +++ b/dbbackup.sh @@ -16,9 +16,10 @@ 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}') +MAILTO="support@comprofix.com" +MAILFROM="support@comprofix.com" +THISSERVER=$(hostname -f) +SMTP="mail.comprofix.com" SUBJECT="$(hostname -f) Database Backup Completed $BAKDATE" BAKDATE=$(date +%Y%m%d) @@ -43,7 +44,7 @@ for db in $databases; do 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 #cat /tmp/dbbackup.msg | mail -s "$SUBJECT" "$MAIL" diff --git a/diskalert.sh b/diskalert.sh index 360aa79..4ff1fe1 100755 --- a/diskalert.sh +++ b/diskalert.sh @@ -5,10 +5,10 @@ # Description: # This script will email when diskspace is high. -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}') +MAILTO="support@comprofix.com" +MAILFROM="support@comprofix.com" +THISSERVER=$(hostname -f) +SMTP="mail.comprofix.com" LOGFILE="/var/log/diskalert.log" THISSERVER=$(hostname -f) @@ -62,7 +62,8 @@ See the logfile for more info: vim $LOGFILE 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 fi diff --git a/nasbackup.sh b/nasbackup.sh index 7b6729b..d5f4553 100755 --- a/nasbackup.sh +++ b/nasbackup.sh @@ -1,15 +1,12 @@ #!/bin/bash -#apps backup downloads fun games movies mp3s tvshows wow -#MAILTO=mmckinnon@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}') +MAILTO="support@comprofix.com" +MAILFROM="support@comprofix.com" +THISSERVER=$(hostname -f) +SMTP="mail.comprofix.com" + -#MAILFROM="$(hostname)@$(dnsdomainname)" SUBJECT="Backup Log `date +%d-%m-%Y`" LOGFOLDER=/var/log/nasbackup LOGFILE=$LOGFOLDER/backuplog-`date +%d-%m-%Y.log` @@ -50,5 +47,5 @@ echo "$(date) [MESSAGE] Backup completed $LOGFILE has been emailed." >> $LOGFILE 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" diff --git a/shorewall-blacklist.sh b/shorewall-blacklist.sh deleted file mode 100755 index b7c9bcf..0000000 --- a/shorewall-blacklist.sh +++ /dev/null @@ -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