how to check disk space


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to check disk space
# 8  
Old 08-24-2010
OK, final solution:
Code:
df -k | awk ' { p=substr($5,1,index($5,"%")-1); if(p+0>=50) print "NOT OK"; else print "OK" }'



---------- Post updated at 09:24 AM ---------- Previous update was at 09:21 AM ----------

If you want to test equality of numbers in shell, you can use:
Code:
if [ "$d" -eq "50" ]

"if [ "$d" == "50" ]" is for testing equality of strings.
# 9  
Old 08-24-2010
Thanks kevin... its working yar..... thank u so much.. but its showing like this..

Code:
bash-3.00$ df -k | awk ' { p=substr($5,1,index($5,"%")-1); if(p+0>=50) print "NOT OK"; else print "OK" }'
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
NOT OK
NOT OK
OK
NOT OK


because its checking all colums ..
Code:
bash-3.00$ df -k
Filesystem            kbytes    used   avail capacity  Mounted on
/dev/dsk/c0t0d0s0    20171281 2580778 17388791    13%    /
/devices                   0       0       0     0%    /devices
ctfs                       0       0       0     0%    /system/contract
proc                       0       0       0     0%    /proc
mnttab                     0       0       0     0%    /etc/mnttab
swap                 11135968    1520 11134448     1%    /etc/svc/volatile
objfs                      0       0       0     0%    /system/object
sharefs                    0       0       0     0%    /etc/dfs/sharetab
/dev/dsk/c0t0d0s1    30254974 3235704 26716721    11%    /usr
/platform/SUNW,Sun-Fire-T200/lib/libc_psr/libc_psr_hwcap1.so.1
                     20171281 2580778 17388791    13%    /platform/sun4v/lib/libc_psr.so.1
/platform/SUNW,Sun-Fire-T200/lib/sparcv9/libc_psr/libc_psr_hwcap1.so.1
                     20171281 2580778 17388791    13%    /platform/sun4v/lib/sparcv9/libc_psr.so.1
fd                         0       0       0     0%    /dev/fd
/dev/dsk/c0t0d0s2    10085260 1686141 8298267    17%    /var
/dev/dsk/c0t2d0s0    10085260 2073979 7910429    21%    /tmp
swap                 11134496      48 11134448     1%    /var/run
/dev/dsk/c0t2d0s2    20171281  555909 19413660     3%    /opt
/dev/dsk/c0t2d0s5    9846556 2804805 6943286    29%    /backup
/dev/dsk/c0t0d0s4    70359009 55329888 14325531    80%    /oracle
/dev/dsk/c0t2d0s1    5043342 3772847 1220062    76%    /export/home
/dev/dsk/c0t2d0s4    30254974  628971 29323454     3%    /opt/ulcm
/dev/dsk/c0t2d0s3    65553610 55899965 8998109    87%    /opt/product



could u make it .. total output? if anyone is not oki.. i want to print NOT OK.
# 10  
Old 08-24-2010
So you want to know which partition is "NOT OK", right?
Code:
df -k | awk ' { p=substr($5,1,index($5,"%")-1); if(p+0>=50) print $NF " is NOT OK, over " p "% of its available space is used."; else print $NF " is OK." }'

# 11  
Old 08-24-2010
Thanks kevin...

i want to print only NOT OK partition like below

ex:
/oracle is NOT OK, over 80% of its available space is used.
/export/home is NOT OK, over 76% of its available space is used.
/opt/product is NOT OK, over 87% of its available space is used

thank you so much...
# 12  
Old 08-24-2010
Then remove the "else print ..." part from the code.
# 13  
Old 08-24-2010
There are at least two errors with your script.

1. The if-line compares with exactly 50. But if your disk is 51%, it will not discover that.

2. Your df-command line will display several lines, if several disks are above 50%, and then your script will not work
# 14  
Old 08-24-2010
Hi, markkusi

For doubt 1, I don't quite understand what you mean. In my script I stripped "%" for the 5th column, and compare the number I get with 50, equals to or above it, it just works like a charm. why don't you think it would discovery that if the disk is used 51%?

For doubt 2, I am still confused.

I didn't have a Solaris system to test my script, so I just copied the input sample Steve posted, it all worked before I posted each response.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Check free disk space in server

Hi, I need about 500G space in one corporate solaris server. However, I am not sure which command to use to check this. There are few volume groups in the server, and I deleted unused, old volume groups to clear some space. However, now I am not sure how to check the free space itself. ... (2 Replies)
Discussion started by: anaigini45
2 Replies

2. Shell Programming and Scripting

Check the disk space then sftp

Hi Everyone, Good Day, Seeking for your assistance to check if the disk capacity reach its usage into 70% then sftp all files in the specific folder. i know only the command df -h, but i don't know where to insert the sftp when it reach 70% Example: Directory: /appl/Files df -h varlock... (2 Replies)
Discussion started by: znesotomayor
2 Replies

3. Shell Programming and Scripting

Check disk space

I am trying a script which will alert if disk space crosses some threshold, i googled it and got some scripts already, but they are not working with my server. The problem is, my filesystem names are big, so the sizes are moving to the second line. just like below any ideas? thanks in advance... (8 Replies)
Discussion started by: karthikeayan
8 Replies

4. Homework & Coursework Questions

Looking to check disk space

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Need to check the disk space and if any portion disk space usage high then write to one file, later will... (5 Replies)
Discussion started by: Jasminshakoor
5 Replies

5. Shell Programming and Scripting

How to suppress the file name when we check for disk space

How to supress the file name when we check for disk space ? I used this command : du -ks /home/dir1/dir2/file.csv it returns 13 /home/dir1/dir2/file.csv Please explain the options too (7 Replies)
Discussion started by: arukuku
7 Replies

6. Shell Programming and Scripting

Check and compare disk space and email it

I am very new to Linux and learning to script. This is for one of my servers at work that I have to keep track off as far as disk space and how it is used. I have tried to go line by line but little things keep chewing me up. I would appreciate any and all help or advice, and Mutt is installed on... (3 Replies)
Discussion started by: sgtjkj
3 Replies

7. Programming

C++: how to check my directory disk space

I have a directory, and I write some files in to that. How to throw the error exception when my directory is full. i.e. there is no disk space (2 Replies)
Discussion started by: SamRoj
2 Replies

8. Solaris

Disk space check

Hi, I have a question regarding finding free space on the disk of a solaris machine. Many mount points are available in my machine. Right now i am using df -b option to get the free disk space available. I have an assignment to check free space on the disk. I pass the directory as a... (6 Replies)
Discussion started by: raghu.amilineni
6 Replies

9. Shell Programming and Scripting

Perl script to check free disk space

hello, I have to check the free space on the disk that would work both on Windows and Unix platform e.g on C: \ for Windows and / on Unix. I could use Unix command 'df ' ( my windows system has Unix emulator cygwin and could run 'df ' as well). But I'd like not to rely on system command but... (1 Reply)
Discussion started by: susja
1 Replies

10. Shell Programming and Scripting

Please help - disk space check script

I have a disk space check script that uses an exceptions file, the only issue with the script is that it does not work with values higher than the FSMAX=85 value. I have a file system that is at 92% and it doesn't change, so I would like to add it to the exceptions file. The exceptions file format... (0 Replies)
Discussion started by: maddhadder71
0 Replies
Login or Register to Ask a Question