Problem in checking space of mount.Please help me


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Problem in checking space of mount.Please help me
# 1  
Old 09-24-2008
Problem in checking space of mount.Please help me

Hi everyone,

I am writing a script. As a part of this script, I wanted to check the space of few mounts, If the space usage percentage of the mount crosses over a certain limit then i wanted to display a warning message. The following is the command

df -k | awk ' { if (($6 == "/export/temp") || ($6 == "/export/temp1") || ($6 == "/export/temp2")) {svalue=substr($5,1,(index($5,"%"))-1);if(svalue >= 48) { print "\nWarning: "$6 " space is " $5 " running out of space"}}}'

when the percentage of space is equal to 100% it is not printing the warning message. If i am not wrong, i think the return value of "substr($5,1,(index($5,"%"))-1" is a string which will be stored in svalue string variable. Then i am comparing the string value of svalue with a interger value. This may be the problem I think so.

can anyone tell me how to correct it? how to convert the string value to integer value and then compare it? or how to do it in a correct way?

Please help me on this.
Thank in advance.
# 2  
Old 09-24-2008
awk automatically converts between string and number representation, and complains if it cannot do that. I believe you could even skip the whole substr thing, and trust awk to parse the number part before the percent sign.

It would perhaps be more idiomatic to use a regular expression for $6, and make it the condition for the rest of the script.

Code:
df -k | awk '$6 ~ /^\/export\/temp/ && $5+0 >= 48 {
    print "Warning: "$6 " space is " $5 " running out of space"}'

I'll leave it to you to ponder on whether "space is running out of space" is a useful thing to say ...

(If you have other /export/temp* partitions than the ones you listed, you'll have to tighten up that regular expression a bit. /^\/export\/temp[12]?$/ would match exactly what you had.

Last edited by era; 09-24-2008 at 03:53 AM.. Reason: Split script over two lines for legibility
# 3  
Old 09-24-2008
Hi ,

I tried as you have said but it is not printing anything,

df -k | awk '$6 ~ /^\/export\/home1/ && $5+0 >= 48 {print "Warning: "$6 " space is " $5 " running out of space"}'

so just to check whether awk parse the number part before the percent sign, i have executed the following command

df -k | awk ' { if (($6 == "/export/home1") || ($6 == "/export/home2")) {svalue=$5+0;print "svalue=" svalue;print "per of space=" $5;}}'

i am getting the output,
svalue=0
per of space =65%
svalue=0
per of space=49%

Any advice please?
# 4  
Old 09-24-2008
Works for me with both mawk and classic awk. Which platform are you on?

If the match you did before didn't work correctly, and this doesn't work, you could try a simple sub(/%/, "", $5) to get rid of the percent sign.
# 5  
Old 09-24-2008
Hi,

Thanks for your quick response.

I am using SunOS 5.8 version. I have tried as you have suggested like

df -k | awk '($6 ~ /^\/export\/home1/) && (sub(/%/, "", $5) >= 48) {
print "Warning: "$6 " space is " $5 " running out of space"}'

then i am getting the syntax error,
awk: syntax error near line 1
awk: bailing out near line

I think it may be a problem since i am trying to change to $5 instead of string variable value,

so i have changed the code to
df -k | awk ' { if ($6 == "/export/home1") {svalue=$5;sub(/%/, "", svalue);print svalue}}'
then also i am getting the same error,
awk: syntax error near line 1
awk: illegal statement near line 1

I am not sure what i am doing wrong. Please advice me on this.

Then i have modified the code the other way,

df -k | awk ''(($6 == "/export/home1") || ($6 == "/export/home2")) {if((substr($5,1,(index($5,"%")-1))+0) >= 5) { print "\nWarning: "$6 " space is " $5 " low Disk space"}}'

The above code is working for me even when the $5 i.e usage percentage of space is 100% also.

I am not sure what was wrong with the earlier code. Please advice.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check the mount space

Hi, When i check the cifs = cifs i could get two dupliates of cifs present in unix. so the system couldnt check. could you please let me know how to make the change code to find out the unique one in the line 6. 1NTBD="/ft/sv/ss" 2check_ntfs() 3{ 4 # Check that the necessary NT areas are... (1 Reply)
Discussion started by: keerthi2016
1 Replies

2. Solaris

UNIX Checking Tape Space

Hello. My name is Alex and I am new to the UNIX environment. One of the things that I do on a daily basis is I perform backups to tape on a Sun Ultra 25. I use DAT72 tape. The tape that is currently in the tape drive has about five database backups within it already. I was just hoping... (19 Replies)
Discussion started by: daddy.torres
19 Replies

3. HP-UX

Vxfs mount: is corrupted. needs checking

Hi Gurus, Please Help me to resolve below issue. OS Version : HP-UX B.11.00 U 9000/800 62830930 When ever i try to mount following logical volumes, it throws me error. mount -a vxfs mount: /dev/datavg1/lvusr40 is corrupted. needs checking vxfs mount: /dev/datavg1/lvusr38 is... (2 Replies)
Discussion started by: Justin John
2 Replies

4. UNIX for Advanced & Expert Users

Checking the space for /archlog mount point script

I have the below shell script which is checking /archlog mount point space on cappire(solaris 10) server. When the space usage is above 80% it should e-mail. When i tested this script it is working as expected. #!/usr/bin/ksh export MAIL_LIST="tlr.voora@zamn.com" export ARCH_STATUS=`df -k... (1 Reply)
Discussion started by: dreams5617
1 Replies

5. Shell Programming and Scripting

Checking the space for /archlog mount point script

I have the below shell script which is checking /archlog mount point space on cappire(solaris 10) server. When the space usage is above 80% it should e-mail. When i tested this script it is working as expected. -------------------------------------------------------------------------... (0 Replies)
Discussion started by: dreams5617
0 Replies

6. Homework & Coursework Questions

Unix space checking script

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: Im still pretty new to this and could really use some help with this task "Write a script to check in the... (12 Replies)
Discussion started by: krolike
12 Replies

7. Linux

Adding space to existing mount

I am on Red Hat Linux 4.7. I am getting this error message: Preparing... ########################################### You have insufficient diskspace in the destination directory (/usr/lib) to install xxxxxxxxxxxxx. The installation requires at least 1.5 GB free on this... (2 Replies)
Discussion started by: jxh461
2 Replies

8. Solaris

Command used for checking space occupied by files & sub-direc's inside a mount in %?

Hi, I want to know the command which can be used for finding the % of disk space occupied by files & sub-folders inside a given mount in Sun Solaris For eg: I have /tmp/ folder when I sat df -k it will give the percentage of space used by /tmp/. Say if I want to see how much % the files &... (2 Replies)
Discussion started by: weblogicsupport
2 Replies

9. UNIX for Dummies Questions & Answers

checking for a space in a file name

hi members... another new probs... i need to check all the zip files in the server and check for a space or "`" in the file name and if found need to remove them and form a zip file. i tried using grep command to check for a space but with out success also when i tried checking for "`" as... (6 Replies)
Discussion started by: madhu_aqua14
6 Replies

10. AIX

Increase in space in mount point.

I am working in AIX 4.3.3 , here when we are doing one activity we ran out of space in one mount point, we need to increase the space in that mout point by reducing it in another mount point, can anybody help me out in carrying this activity. Vipin (3 Replies)
Discussion started by: vipin77
3 Replies
Login or Register to Ask a Question