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!

Need Script for monitoring directory growth ...

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hi folks,

I'd like to use a script that monitors a certain directory (including all subdirectories) and as soon as there are any new files written into this directory sends out an email ...

I'm afraid I'n not much of a scripter ...
Is there anyone who can help me ?

Thanks in advance !

Regards, Thomas
 
Read the nmon guide. It will tell you how to script data collection for certain resources. It then puts the data in a form that the nmon analyzer will read into Excel and graph everything out for you.
 
Hi folks,

it's a great tool :)
I just downloaded and tested it and it's awesome ...
We certainly have good use for it !
Thanks a lot !

But the problem here is that I need some kind of script telling me via email as soon as there are files being written into a certain directory or any of it's subdirectories ...

Regards
Thomas
 
Do you want to monitor size or writes? If you want to monitor the % full, that can be done with WSM not to mention a bunch of other scripts out there. I guess if you want to monitor file writes, you could modify one of those scripts to e-mail you everytime the free space drops ...
 
vi disk_check.sh

df -k|grep 108|awk '{print $4}' > file1
cut -c 1-2 file1 > file2

a=`cat file2`

if [ $a -ge "20" ];then
echo "files exist"
else
echo "No Files"
fi

:qw!

** replace 108 with your filesytem name **
** replace echo with echo "Disk activity" | /usr/bin/mailx -c "you@youmail.com"

Run it from crontab

crontab -e

0,5,10,15,20,25,30,35,40,45,50,55 * * * * disk_check.sh
:wq!

Not perfect:Not tested

--
| Mike Nixon
| Unix Admin
|
----------------------------
 
mrn,

sometimes the files that are written to the directory are small enough not to affect the percentage of the FS usage.
I would count the files/dirs once in a awhile,and issue an email if the count grows:
====================================
#!/bin/ksh

#NUMFILES = this is the file that holds last number of files and directories
#NEW_NUMFILES = this is the file that holds the new number of files and directories

###### main ######
#add this script to the crontab
crontab –l |grep “$0” > /dev/null
if [[ $? != 0 ]] ;then
crontab –l > /tmp/crontab1
echo “0,5,10,15,20,25,30,35,40,45,50,55 * * * * `pwd`/$0” >> /tmp/crontab1
crontab /tmp/crontab1
fi

#change /home to your FS name
path1=”/home”

#Update the log with the new number of files in the path
ls -latR $path1|wc –l > /NEW_NUMFILES
#mail if the new number is bigger then the previous one
if (( `cat /NEW_NUMFILES` > `cat /NUMFILES` )) ;then
mail –s “New file/directory were created in the $path1” youname@ppp.com < /NEW_NUMFILES
fi
cp /NEW_NUMFILES /NUMFILES


&quot;Long live king Moshiach !&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top