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?
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.
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
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.
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)