Folder level size monitoring


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

Hi All,

I have a requirement to monitor the sub-directories under /home in a way that if the the folder size increases by 30 GB in a span of like an hour then it needs to send email alerts listing what as the actual size was and what's the current size which the subject listing the sub-directory name. Can anyone help me with this script. It's a redhat server. Have tried few scripts from this and all give some or the other error which I cannot comprehend since I am totally totally new to scripting.

Thanks,
# 2  
Old 10-04-2011
Not tested .. this code is just for this scenario ..
Code:
while [ 1 ]
do
        find /home -type d -size +30000000 -print > find_contents
        [ -s "find_contents" ] && mailx -s "Directories having 30GB more size" abc@xyz.com < find_contents
        sleep 3600 ## sleep for 1 hr
done

# 3  
Old 10-04-2011
Hi Jayan,

Thanks for the script. I need to convert this into a bash script...how do I do that?

Regards
# 4  
Old 10-04-2011
Put the above code in a file and run it ...
# 5  
Old 10-04-2011
If you are looking for differences since last run of over 30Gb rather than just current size, you could probably write a process using the output from the du command, assuming that it is available in your OS.

Depending how you want to monitor, you could try something like (in ksh):-
Code:
#!/bin/ksh

current_file=/tmp/current    # Pick what you like here
previous_file=/tmp/previous

mv $current_file $previous_file
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
      # Take some action
   fi
done



Does that help?





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

Have tried you code....but when I run it....it seems that that code does not stop running. After running...it does not give me back the shell prompt. Not sure whether I am doing it wrong here.

Hi Robin,

I will test you code and let you know.

Thanks
# 7  
Old 10-04-2011
Shailesh6,

Jayen's code is in an infinite loop.


Mine does require that you are able to read all the subdirectories of /home, and their sub-directories, and their's, and theirs ..........

Perhaps a tool like sudo for the du command would be good to elevate your privileges for the execution of that alone.




Robin
Liverpool/Blackburn
UK

Last edited by rbatte1; 10-04-2011 at 10:28 AM.. Reason: wrong word used, corrected indefinite with infinite.
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

Featured Tech Videos