Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix script help

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a file log file that collects data only when there are database problems. I want a unix script that will let me know when the file changes (size) , will tail off the the ending of the file and then send me an email notifying me that there may be a problem. The last two parts I can do but the changing of file size is what I need help on.


 
Here is an idea to get you started.
#!/bin/sh

logfile="/logdir/logfile" #your log here.
DB="/tmp/clobber.txt" #random rw file here.


size=`ls -l $logfile | awk '{print $5}'` #current size
osize=`awk 'NR == 1 {print $0}' $DB` #recorded size

action() #tests for DB file, creates and reports
{
if [ ! -e $DB ]
then
echo $size > $DB ; echo -e "SizedUP.`date`" | logger
elif [ -z $DB ]
then
echo "$DB was clobbered."
exit 1 > /dev/null

fi
return 0
}

mtest() #tests current and old sizes.
{
if test `echo $size` != `echo $osize`
then
echo "errors found." | mail user@host
fi
}

action ; mtest

I make no claims to be a programmer, and though this works there must be a better way. I have seen this post just sitting here for days so I decided to reply. You can just use the core ideas. I would not suggest using this script.
;}

Luck


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top