Showing posts with label Utilities. Show all posts
Showing posts with label Utilities. Show all posts

Monday, February 2, 2009

Check Available Disk Space and Notify

Here's some handy bash script to notfiy support when we are running low on disk space.


#!/bin/bash
#
# Description:Checks the available space for the disk mounted as / (root)
# If disk space is less than 10GB it will send out a notification
#

# Send emails to these people
EMAILID=support@mydomain.com

# Min Free Space
MINSPACE=10485760

# Get the space available
FREESPACE=`df / | awk '{ if( NR == 2) print $4 }'`

# Send email if required
if [ $FREESPACE -le $MINSPACE ];
then
logger "Warning: Root Drive Running Out Of Disk Space [${FREESPACE}KB]"
mail -s 'My Favourite Production Server Disk Space' ${EMAILID} << EOF
My Favourite Production server root drive is running out of disk space. Current free space is ${FREESPACE} KB @ $(date)
EOF
fi

Wednesday, April 9, 2008

Truncate a file

While setting up Apache HTTP Server to rotate logs I came across an interesting problem. How would you truncate a file? The trivial solution that I came up with was


[root@lambda ~]# rm -f /var/log/httpd/foo.log
[root@lambda ~]# touch /var/log/httpd/foo.log


Unfortunately this doesn't work. The HTTP Server ceases logging to the file unless there is a server restart. After prying around the web I came across some interesting tricks but the one that stood out was:


[root@lambda ~]# :> /var/log/httpd/foo.log

TCP Dump

A very convenient way to find out traffic content on a particular port.


tcpdump -l -i eth0 -w - src or dst port 3306 | strings