Go Back   Singapore Web Hosting Talk > LEARNING CENTER > Server Administration

Server Administration General dedicated servers administration topics.

Reply
 
Thread Tools
Old 07-11-2003, 17:46   #1
choon
SGWHT Senior Member
 
Join Date: 01-07-2002
Location: Singapore
Posts: 488
choon has a spectacular aura aboutchoon has a spectacular aura about
HOW TO: Setup Disk Check, dmesg, secure log, messages log etc... email notification

Hi everyone,

This is part of my laziness in term of system administration for viewing some log files and normal admin tasks in Red Hat Linux. Please note that you can't really refrain yourself from logging in the server and do some manual admin tasks.

You can follow what I have done with/without modification.

Again, follow this at your own risk. I am not responsible for any damages caused to you. You have been warned!!!

You have to gain root access to your server to preform the following... ...

Step 1: Setup Disk Space Notification
This is setup to email you about the hard disk usage daily in cronjob.

Copy and paste the following content and save it as /etc/cron.daily/choon-diskcheck:
Code:
#!/bin/sh
#
# This is a shell script to mail the system administrator daily
# about the disk usage in cronjob.
#
# Created by Giam Teck Choon
#

TMPFILE='/tmp/diskcheck'
MAILTO='PLEASE_ENTER_YOUR_EMAIL_ADDRESS_HERE'
TITLE="Disk Space Check performed on Server `hostname` dated `date`"

# Create the tmpfile first
touch $TMPFILE

# Generate the message
echo " " >> $TMPFILE
echo "------------------------------------------------------------------------------" >> $TMPFILE
echo "*** $TITLE ***" >> $TMPFILE
echo "------------------------------------------------------------------------------" >> $TMPFILE

# Redirect all output to the tmpfile
df -h >> $TMPFILE 2>&1
if [ -f "$TMPFILE" ] ; then
        cat $TMPFILE | mail -s "$TITLE" $MAILTO
        rm -f $TMPFILE
fi
Step 2: Send dmesg to you daily
Copy and paste the following content and save it as /etc/cron.daily/choon-dmesg:
Code:
#!/bin/sh
#
# This is a shell script to mail root the dmesg daily
# in cronjob.
#
# Created by Giam Teck Choon
#

MAILTO='PLEASE_ENTER_YOUR_EMAIL_ADDRESS_HERE'
TMPFILE='/tmp/dmesg'
TITLE="dmesg on Server `hostname` dated `date`"
# Create the tmpfile first
touch $TMPFILE

# Generate the message
echo " " >> $TMPFILE
echo "------------------------------------------------------------------------------" >> $TMPFILE
echo "*** $TITLE ***" >> $TMPFILE
echo "------------------------------------------------------------------------------" >> $TMPFILE

# Redirect all output to the tmpfile
dmesg >> $TMPFILE 2>&1

if [ -f "$TMPFILE" ] ; then
        cat $TMPFILE | mail -s "$TITLE" $MAILTO
        rm -f $TMPFILE
fi
Step 3: Send content in /var/log/messages to you daily
This will email the content in file /var/log/messages to you daily. Copy and paste the following content and save it as /etc/cron.daily/choon-var-log-messages:
Code:
#!/bin/sh
#
# This is a shell script to mail root the /var/log/messages daily
# in cronjob.
#
# Created by Giam Teck Choon
#

TMPFILE='/tmp/var-log-messages'
MAILTO='PLEASE_ENTER_YOUR_EMAIL_ADDRESS_HERE'
LOG='/var/log/messages'
TITLE="$LOG on Server `hostname` dated `date`"

# Create the tmpfile first
touch $TMPFILE

# Generate the message
echo " " >> $TMPFILE
echo "------------------------------------------------------------------------------" >> $TMPFILE
echo "*** $TITLE ***" >> $TMPFILE
echo "------------------------------------------------------------------------------" >> $TMPFILE

# Redirect all output to the tmpfile
cat $LOG >> $TMPFILE 2>&1
if [ -f "$TMPFILE" ] ; then
        cat $TMPFILE | mail -s "$TITLE" $MAILTO
        rm -f $TMPFILE
fi
Step 4: Send content in /var/log/secure to you daily
This will email the content in file /var/log/secure to you daily. Copy and paste the following content and save it as /etc/cron.daily/choon-var-log-secure:
Code:
#!/bin/sh
#
# This is a shell script to mail root the /var/log/secure daily
# in cronjob.
#
# Created by Giam Teck Choon
#

TMPFILE='/tmp/var-log-secure'
MAILTO='PLEASE_ENTER_YOUR_EMAIL_ADDRESS_HERE'
LOG='/var/log/secure'
TITLE="$LOG on Server `hostname` dated `date`"

# Create the tmpfile first
touch $TMPFILE

# Generate the message
echo " " >> $TMPFILE
echo "------------------------------------------------------------------------------" >> $TMPFILE
echo "*** $TITLE ***" >> $TMPFILE
echo "------------------------------------------------------------------------------" >> $TMPFILE

# Redirect all output to the tmpfile
cat $LOG >> $TMPFILE 2>&1
if [ -f "$TMPFILE" ] ; then
        cat $TMPFILE | mail -s "$TITLE" $MAILTO
        rm -f $TMPFILE
fi
Step 5: Find nouser/nogroup files notification
Copy and paste the following content and save it as /etc/cron.daily/choon-find-nouser-nogroup:
Code:
#!/bin/sh
#
# This is a shell script to mail the system administrator daily
# about nouser/nogroup files in cronjob.
#
# From http://tldp.org/HOWTO/Security-HOWTO/file-security.html :
#
# Unowned files may also be an indication an intruder has accessed your system.
# You can locate files on your system that have no owner, or belong to no group
# with the command:
#
# find / \( -nouser -o -nogroup \) -print
#
# Created by Giam Teck Choon
#

TMPFILE='/tmp/find-nouser-nogroup'
MAILTO='PLEASE_ENTER_YOUR_EMAIL_ADDRESS_HERE'
TITLE="nouser/nogroup Files Check performed on Server `hostname` dated `date`"

# Create the tmpfile first
touch $TMPFILE

# Generate the message
echo " " >> $TMPFILE
echo "------------------------------------------------------------------------------" >> $TMPFILE
echo "*** $TITLE ***" >> $TMPFILE
echo "------------------------------------------------------------------------------" >> $TMPFILE

# Redirect all output to the tmpfile
find / \( -nouser -o -nogroup \) -print >> $TMPFILE 2>&1
if [ -f "$TMPFILE" ] ; then
        cat $TMPFILE | mail -s "$TITLE" $MAILTO
        rm -f $TMPFILE
fi
Step 6: Find .rhosts files and notify you daily
Copy and paste the following content and save it as /etc/cron.daily/choon-find-rhosts:
Code:
#!/bin/sh
#
# This is a shell script to mail the system administrator daily
# about .rhosts file in cronjob.
#
# From http://tldp.org/HOWTO/Security-HOWTO/file-security.html :
#
# find / -name .rhosts -print
#
# Created by Giam Teck Choon
#

TMPFILE='/tmp/find-rhosts'
MAILTO='PLEASE_ENTER_YOUR_EMAIL_ADDRESS_HERE'
TITLE=".rhosts Files Check performed on Server `hostname` dated `date`"

# Create the tmpfile first
touch $TMPFILE

# Generate the message
echo " " >> $TMPFILE
echo "------------------------------------------------------------------------------" >> $TMPFILE
echo "*** $TITLE ***" >> $TMPFILE
echo "------------------------------------------------------------------------------" >> $TMPFILE

# Redirect all output to the tmpfile
find / -name .rhosts -print >> $TMPFILE 2>&1
if [ -f "$TMPFILE" ] ; then
        cat $TMPFILE | mail -s "$TITLE" $MAILTO
        rm -f $TMPFILE
fi
Step 7: Chmod all the above created files to executable
Code:
chmod +x /etc/cron.daily/choon-*
Ok, that's all for this time and hope this helps someone

Thanks.

Kindest regards,
__________________
Giam Teck Choon
System Administrator
Join my community today at choon.NET Community to share server related tips and tricks!
External/One-Year WHM/cPanel licenses | Linux/FreeBSD Server Management | Xen VPS Solutions (with/without WHM/cPanel or DirectAdmin)
choon is offline   Reply With Quote

Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump




All times are GMT +8. The time now is 11:58.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright (C) 2002-2015 Brought to you by Singapore Web Hosting Talk (SGWHT). All Rights Reserved.