Script to check file system size


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to check file system size
# 1  
Old 09-29-2010
Script to check file system size

Dears,
the output of this command
Code:
df -h | tr -s ' ' | cut -f5 -d' '

is
Code:
capacity
24%
0%
0%
0%
0%
1%
0%
24%
24%
0%
93%
1%
1%
10%
6%
60%
1%
19%
22%
10%
10%
48%
3%

what i want to do put this out put in if condition there it find 90% send mail to xxx@hotmail.com or something like that

Last edited by zaxxon; 09-29-2010 at 11:23 AM.. Reason: Rephrasing subject, was a bit unclear
# 2  
Old 09-29-2010
try this methods
Code:
FILESYSTEM=/path/subpath
if [ `df -k ${FILESYSTEM} | grep -v Use | awk '{ print $5 }' | sed 's/%//'` -gt 80 ]; then
mailx -s "File System full" mailid@domain.com
fi

# 3  
Old 09-29-2010
The tr does not subsitute anything since a parameter is missing. Also cutting out the percent value without the corresponding file system is useless information in my eyes.

So here another approach:
Code:
#!/bin/bash

MAILTO=you@your.org
TMPFILE=/tmp/fs_size123.tmp
THRESHOLD=90
SUBJ="$(uname -n): File system report"

rm -f $TMPFILE > /dev/null 2>&1

df -h|\
awk -v t=$THRESHOLD 'NR>1 {if($5 > t){_[$NF]=$5}} END{for(a in _) printf("%-8s%-s\n", _[a],a)}' > $TMPFILE

if [[ -s $TMPFILE ]]; then
     echo $TMPFILE| mail -s "$SUBJ" $MAILTO
fi

exit 0

Output in the mail's body would like:
Code:
92%     /var
96%     /data/bla


Last edited by zaxxon; 09-29-2010 at 12:01 PM.. Reason: typo
# 4  
Old 09-29-2010
Hi zaxxon.
i am facing this error when i try to run you code
Code:
awk: syntax error near line 1
awk: bailing out near line 1

# 5  
Old 09-29-2010
Could be a problem with the version of awk. If you are using Solaris, you might want to use nawk or /usr/xpg4/bin/awk, or if available gawk.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to check for file size and then sftp

noted down (44 Replies)
Discussion started by: mirwasim
44 Replies

2. Emergency UNIX and Linux Support

Script to fill the file system mount with empty files to desired size

We are regularly using for our testing, where we are manually filling up the mount with desired size with following command dd if=/dev/zero of=file_2GB bs=2048000 count=2000 We are planning to automate the task where taking input for % of size as one input and the name of the file system... (8 Replies)
Discussion started by: chandu123
8 Replies

3. Shell Programming and Scripting

Help with a shell script to check /var file system

deleting (0 Replies)
Discussion started by: fretagi
0 Replies

4. Shell Programming and Scripting

Perl Script to check file date and size

Hi guys, i am new to perl. I started reading the perl documents and try to come up with some logic. I am trying to create a script that would go into a location, search for todays files, then searches for all .txt files from today. If todays not found, its an error If file size is less... (26 Replies)
Discussion started by: DallasT
26 Replies

5. Windows & DOS: Issues & Discussions

Check the file size using Batch script in windows

Hi, I need to check the file size using a batch script. Pls advise. (0 Replies)
Discussion started by: krackjack
0 Replies

6. Solaris

Directory size larger than file system size?

Hi, We currently have an Oracle database running and it is creating lots of processes in the /proc directory that are 1000M in size. The size of the /proc directory is now reading 26T. How can this be if the root file system is only 13GB? I have seen this before we an Oracle temp file... (6 Replies)
Discussion started by: sparcman
6 Replies

7. Shell Programming and Scripting

shell script to check file size greater than 50M

Hi All, OS:AIX 64 bits using korn shell. Requirement: shell script to check file size greater than 50M and send mail alert. Thanks for your time! Regards, (3 Replies)
Discussion started by: a1_win
3 Replies

8. Shell Programming and Scripting

File System Check using shell script !!!

Hi Guys I m posing this new thread as I didnt get satisfactory result after running search here. My requirement is very simple (using shell script) I need to findout what all file systems are mounted -> Then I need check the health of that file system - by disk usage & by doing a simple... (8 Replies)
Discussion started by: csaha
8 Replies

9. Shell Programming and Scripting

Script to Delete temp files and check file system

Hi all, new to the threads as well as Unix/Linux. I need to create a script that will delete any temporary files as well as check the files on the system for errors or corruption. This is what I have so far and I'm sure that I'm missing things or have the wrong commands. I'm not sure where to go... (3 Replies)
Discussion started by: Bwood1377
3 Replies

10. Shell Programming and Scripting

unix script to check whether particular file exists and to find its size

I want to find the size of particular file exists in a particular directory and i wnt to zip it. In the below mentioned code it should check the MQ.log in the particular directory.Please correct my code so that it will check for particular MQ.log but i could not able to check whether the... (9 Replies)
Discussion started by: Balachandar
9 Replies
Login or Register to Ask a Question