Folder level size monitoring


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Folder level size monitoring
# 8  
Old 10-04-2011
Robin,

If I want to mail the alert condition to a email address what would my code look like....I mean can you replace the Take Some action with some code that would send an alert to an email address with a particular subject. And with current_file=/tmp/current and previous_file=/tmp/previous am I supposed to given a directory path that I want to monitor? I want to do it for all the directory under /home and I am performing this testing with root user.

Thanks
# 9  
Old 10-04-2011
For the e-mail, it depends what you want to send and who to.

The files mentioned are just files for this script to run and do it's work. The key bit is being in the directory/filesystem you want to be monitoring, in this case it's /home as in listed in the du command.

If the email is to the directory owner, then it depends if you have an e-mail address (or could build one) for each user. Perhaps you have it as the user comment so you could extract it from /etc/passwd (usually field 5 I think) Once you have determined the e-mail address, your command could be something like:-
Code:
......
if [ $delta_size -gt 3072000 ]    # I think that this is 30Gb~ish
   then
      echo "You have a quickly growing directory called $dir1\n\nThe administrator." | mail -s "Subject line in here" $email_address
fi

If your email is not based on the same server, then you will need to configure the /etc/sendmail.cf file, however this probably just means setting a DS record (which is commented out by default) to name your e-mail server or some relay that will accept smtp and route it on for you. Find the line that is for the DS statement and uncomment it, adding in your mail server, e.g.:-
Code:
DSyour.mail.server

Make sure that the address can be resolved (DNS prefereably) and that you can open port 25. If you try:-
Code:
telnet your.mail.server 25

... then you should get a HELO reply rather than a timeout.



Does this help a bit more?




Robin
Liverpool/Blackburn
# 10  
Old 10-04-2011
Hi Robin,

This is help a lot lot more...my email is not based on the same server so I will need to make change in the sendmail.cf. I will check this an let you know.

Thanks.
# 11  
Old 10-04-2011
Quote:
Originally Posted by rbatte1
Code:
du -ks /home/* > $current_file
paste $previous_file $current_file | while read prev_size dir1 curr_size dir2
do
   ((delta_size=$curr_size-$prev_size))
   if [ $delta_size -gt 3072000 ]    # I think that this is 30Gb~ish
   then

Caveat: That approach will silently implode if files or directories are added to or removed from /home.

Regards,
Alister

Last edited by alister; 10-04-2011 at 01:01 PM..
# 12  
Old 10-04-2011
Yes, agreed & point taken. I suppose we could cover it off by checking that "$dir1" = "$dir2", but then how you carry on could be a nightmare. Smilie

The alternate would be to read the first file and then get the approptaite record from the second, but that's a much bigger thing to think about.

Anyone facy taking it on? Smilie



Robin
# 13  
Old 10-04-2011
Hi Guys,

Please give me brief how the original script given by Robin would cause any implode?

Thanks
# 14  
Old 10-04-2011
Quote:
Originally Posted by Shailesh6
Hi Guys,

Please give me brief how the original script given by Robin would cause any implode?

Thanks
You would probably learn more if you tried it for yourself. Run the script. Then delete and/or add a directory. Run the script again. Perform the test with pathnames that occur in early in the sort order for maximum effect.

Quote:
Originally Posted by rbatte1
Code:
du -ks /home/* > $current_file
...
   if [ $delta_size -gt 3072000 ]    # I think that this is 30Gb~ish

Since those are kilobytes, that's actually closer to 3 gigabytes.

Regards,
Alister
This User Gave Thanks to alister For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting folder more than 100K size

Hi , I am trying to get the folder details having size more than sme specified value and also the name of the folder should be like TEST. so 1. In the current directory search for all the folders having name like TEST 2. Print the list of the folder names having size more than 100... (3 Replies)
Discussion started by: Anupam_Halder
3 Replies

2. UNIX for Dummies Questions & Answers

General question about folder level permissions

How is the level of access on a particular folder determined? I have heard (its just hearsay so am not particularly sure of it) that the access a particular user/group has to a low level directory is also affected by the level of access granted to the user/group on its parent directories. e.g. ... (1 Reply)
Discussion started by: jawsnnn
1 Replies

3. Shell Programming and Scripting

Log folder size monitoring script

Hi All, Can anyone refer to me a readymade script for the purpose of log folder size monitoring script. Example : I have a log folder of size 10 G, and as the logs keep accumulating the folder gets full and i have to manually zip/remove the files in order to keep the server running. Something... (1 Reply)
Discussion started by: findjai
1 Replies

4. UNIX for Dummies Questions & Answers

Network monitoring at boot level.

Whenever i start my server it takes app 2 minutes to get into network (After starting the network service on boot). I inquire the network guys for possible causes but they say it will need both side monitoring . One is switch side and the second is server side. I m not sure how do i check... (6 Replies)
Discussion started by: pinga123
6 Replies

5. UNIX for Dummies Questions & Answers

Redirect with htaccess to upper level folder, how to?

Hello, Well I have a web with a very bad structure (a vBulletin forum) and I want it redirected to a newer folder in the same server but with a upper level folder. Current structure is: https://www.unix.com/vbulletin/upload/index.php And I want it to be:... (0 Replies)
Discussion started by: Rafaweb
0 Replies

6. UNIX for Dummies Questions & Answers

find files on first level folder

Hi: I have: folderA |----folderB |----folder1 |----folder2 |----folder3 |----folder3.1 Question: How can I find *.txt ONLY from /folderA/folderB/ and not the others folder1,2,3?? I tried: find... (8 Replies)
Discussion started by: iga3725
8 Replies

7. Cybersecurity

Ubuntu folder level security

I have installed ubuntu. And I have create users ans groups. Suppose if the user enter into through Putty SSH. He should have access only to home folder and cannot move to other than $HOME. User should not able to root files and /$ files. Kindly provide solution. Regards Vasanth kumar (3 Replies)
Discussion started by: vasanthrj
3 Replies

8. UNIX for Dummies Questions & Answers

size of a folder ?

hi, is possible to calculate the size of a folder using ls ? ls -s works only for files.. thanks (2 Replies)
Discussion started by: aneuryzma
2 Replies

9. Shell Programming and Scripting

operation on a folder level

hi, need help in writing a script in perl. requirement : 1. Search for the files in a particular folder 2. search for a string in the file names 3. Delete the file which matches the string. Ex: if the folder is C:\TEST and the folder has 5 files like 2009ABCG.txt 2009MNO.txt... (2 Replies)
Discussion started by: adityamahi
2 Replies

10. UNIX for Dummies Questions & Answers

Need help in finding Folder Size

Hi, I would like to find the size of a folder. When I run the command du -k It is going through all the sub-folder and files and taking really much time. Is there any command to get the complete directory size without showing the sub-folder and file size. Appreciate your response. ... (3 Replies)
Discussion started by: TonySolarisAdmi
3 Replies
Login or Register to Ask a Question