diff --git a/README.md b/README.md index ee7863c..fc2486b 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,12 @@ To send emails the sendEmail package is required Change the following lines in scripts that send emails -Edit the following for emails: +MAILFROM is set to determine the server name and domain name for the server and generate and email for it to determine where the email is coming from. This can be changed to specify an email address or you can leave it to generate one. +
-MAILTO="support@comprofix.com"
-SMTP=mail.comprofix.com
-MAILFROM="support@comprofix.com"
+MAILTO=user@example.com
+SMTP=mail.example.com
+MAILFROM=$(hostaname)@$(dnsdomainname)
#### 00logwatch
@@ -27,7 +28,7 @@ ln -s $(pwd)/00logwatch /etc/cron.daily
#### check_updates_deb_sh
-This script checks for updates on your debian system. If any updates are found it will download them ready for Installation and an email will be sent to an email address specified
+This script checks for updates on your Debian based systems. If any updates are found it will download them ready for Installation and an email will be sent to an email address specified
Installation
diff --git a/check_updates_deb.sh b/check_updates_deb.sh
index c811297..5855e4a 100755
--- a/check_updates_deb.sh
+++ b/check_updates_deb.sh
@@ -16,12 +16,11 @@
MAILTO="support@comprofix.com"
SMTP=mail.comprofix.com
+MAILFROM="$(hostname)@$(dnsdomainname)"
AUTOUPDATE="no"
LOGFILE="/var/log/server_maint.log"
-THISSERVER=`hostname --fqdn`
-MAILFROM="$(hostname)@$(dnsdomainname)"
-
+THISSERVER=$(hostname -f)
#
# End of user configuration section
@@ -33,32 +32,32 @@ 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
+if [ $(id -u) -ne 0 ]
+then
+echo "You need to be root to run this script."
+ exit 1
fi
startlogging() {
echo $DASHES2 >> $LOGFILE
- echo "$0 started running at `date`" >> $LOGFILE
+ echo "$0 started running at $(date)" >> $LOGFILE
echo $DASHES2 >> $LOGFILE
}
stoplogging() {
- echo "`date` [MESSAGE] $0 finished runnning" >> $LOGFILE
+ echo "$(date) [MESSAGE] $0 finished runnning" >> $LOGFILE
echo $DASHES >> $LOGFILE
}
check_return() {
if [ "$?" -ne "0" ]
then
- echo "`date` [ERROR] $1 failed to run" >> $LOGFILE
+ echo "$(date) [ERROR] $1 failed to run" >> $LOGFILE
send_error_email $1
stoplogging
exit 1
fi
- echo "`date` [SUCCESS] $1 ran without error" >> $LOGFILE
+ echo "$(date) [SUCCESS] $1 ran without error" >> $LOGFILE
}
send_error_email() {
@@ -72,7 +71,7 @@ Whilst running the update script ($0) on $THISSERVER there was a problem.
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:
+Please log in via ssh (e.g. ssh root@$(hostname -f)) and check the log file:
vim $LOGFILE
@@ -100,7 +99,7 @@ do
done
# End IP Address stuff
-
+
startlogging
@@ -122,7 +121,7 @@ fi
if [[ -z $PACKAGES_TO_BE_UPGRADED ]]
then
- echo "`date` [MESSAGE] No packages need updating." >> $LOGFILE
+ echo "$(date) [MESSAGE] No packages need updating." >> $LOGFILE
else
echo "
@@ -134,7 +133,7 @@ $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:
+To update the server log in via ssh (e.g. ssh root@$(hostname -f)) and run the following command:
apt-get upgrade
@@ -144,7 +143,7 @@ Regards. " >/tmp/servermail.msg
sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "[$THISSERVER] server may need some updates applied" -m "$(cat /tmp/servermail.msg)"
- echo "`date` [MESSAGE] Packages need updating email sent to $MAILTO" >> $LOGFILE
+ echo "$(date) [MESSAGE] Packages need updating email sent to $MAILTO" >> $LOGFILE
fi
stoplogging
diff --git a/diskalert.sh b/diskalert.sh
index 7c4568c..d5cb8a3 100755
--- a/diskalert.sh
+++ b/diskalert.sh
@@ -7,13 +7,13 @@ MAILFROM="$(hostname)@$(dnsdomainname)"
startlogging() {
echo $DASHES2 >> $LOGFILE
- echo "$0 started running at `date`" >> $LOGFILE
+ echo "$0 started running at $(date)" >> $LOGFILE
echo $DASHES2 >> $LOGFILE
}
stoplogging() {
- echo "`date` [MESSAGE] $0 finished runnning" >> $LOGFILE
+ echo "$(date) [MESSAGE] $0 finished runnning" >> $LOGFILE
echo $DASHES >> $LOGFILE
}
@@ -36,12 +36,12 @@ do
let space=`df -Pk $i | grep -v ^File | awk '{printf ("%i", $5) }'`
if [ $space -le 89 ]
then
- echo "`date` [MESSAGE] Disk space usage on $i acceptable. $space% currently in use." >> $LOGFILE
+ echo "$(date) [MESSAGE] Disk space usage on $i acceptable. $space% currently in use." >> $LOGFILE
fi
if [ $space -ge 90 ]
then
-echo "`date` [WARNING] $i is running out of disk space. $space% currently in use." >> $LOGFILE
+echo "$(date) [WARNING] $i is running out of disk space. $space% currently in use." >> $LOGFILE
echo "
Hello,
@@ -54,20 +54,10 @@ See the logfile for more info: vim $LOGFILE
Regards, " >/tmp/diskalertmail.msg
cat /tmp/diskalertmail.msg | sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "[$THISSERVER] is running out of disk space"
-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
done
stoplogging
-
-
-
-
-
-
-
-
-
-
diff --git a/nasbackup.sh b/nasbackup.sh
index e2bdb52..21f802a 100755
--- a/nasbackup.sh
+++ b/nasbackup.sh
@@ -7,7 +7,7 @@ MAILTO=mmckinnon@comprofix.com
SMTP=mail.comprofix.com
MAILFROM="$(hostname)@$(dnsdomainname)"
-BODSUBJECT="Backup Log `date +%d-%m-%Y`"
+BODSUBJECT="Backup Log `date +%d-%m-%Y`"
LOGFOLDER=/var/log/nasbackup
N_DAYS=7
@@ -15,17 +15,16 @@ N_DAYS=7
LOG=$LOGFOLDER/backuplog-`date +%d-%m-%Y`.log
echo "****************************************************************" > $LOG 2>&1
-echo " Start Backup `date` " >> $LOG 2>&1
+echo " Start Backup $(data) " >> $LOG 2>&1
echo "****************************************************************" >> $LOG 2>&1
#rsync -urtlPO --delete --exclude 'kvm' /data/ /media/nas/ >> $LOG 2>&1
rsync -urtlOv --partial --delete --exclude 'kvm' /data/ /media/nas/ >> $LOG 2>&1
echo "****************************************************************" >> $LOG 2>&1
-echo " Finished Backup `date` " >> $LOG 2>&1
-echo "****************************************************************" >> $LOG 2>&1
+echo " Finished Backup $(date) " >> $LOG 2>&1
+echo "****************************************************************" >> $LOG 2>&1
sendemail -o tls=no -f "NAS BACKUP <$MAILFROM>" -t $MAILTO -u "$BODSUBJECT" -m "$BODSUBJECT" -a $LOG -s $SMTP >> $LOG 2>&1
find $LOGFOLDER/* -mtime +$N_DAYS -exec rm {} \;
-