Creating a shell script to check filesystem space


 
Thread Tools Search this Thread
Operating Systems AIX Creating a shell script to check filesystem space
# 8  
Old 06-07-2006
Got it working with:

Code:
#!/bin/ksh
 
used_space=0
mount_point=${1:-"/arch_nb"}
threshold=${2:-65}
 
used_space=`df -k $mount_point | grep -v "^Filesystem" | awk {'print $4'} |sed '
s/%//'`
print "Free Space available under \"$mount_point\" is `expr 100 - $used_space`%.
\n"
 
if [ $used_space -gt $threshold ]
then
   print "Space Utilization on \"$mount_point\" has exceeded the threshhold of $
{threshold}%.\n"
else
   print "Free space on \"$mount_point\" is in normal parameters."
fi

...it turns our that the original statement was returning the header from the "df -k" command in the form of "Iused". This was screwing up the expression in the next line. Thanks to all who helped.
# 9  
Old 06-07-2006
probably best check you've got the right field. I can't remember off hand but df -k might give you free inodes rather than free space hence the Iused header. Try df -I instead and check which field the %free is and adjust your awk statement accordingly.

Smilie
# 10  
Old 06-10-2006
Good idea...thanks.
# 11  
Old 06-18-2006
Quote:
Originally Posted by heprox
When I run the command:

Code:
df -k $mount_point | grep % | awk {'print $5'} | sed 's/%//g'

...assuming I assign the value of "/tmp" to "$mount_point" I get:

Code:
x-4-1-test# df -k /tmp | grep % | awk {'print $5'} | sed 's/%//g'
Iused
774

...its returning a value (although it contains the "Iused" as well? I get the exact same result when I run the command:

Code:
df -k /tmp | grep % | awk '{print $5}' | sed 's/%//g'

...so I dont think the problem is in the qoutes? The problem I think exists in the expression when AIX interprets the "expr" line:

Code:
expr 100 - $used_space`%.\n


you can try

df -k /tmp|grep %|awk 'NR>1{print $3}'|sed 's/%//g'
instead of
df -k /tmp|grep %|awk '{print $5}'|sed 's/%//g'

Last edited by zfengs; 06-18-2006 at 11:15 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filesystem alert shell script not working!!

Hi All, My below shell script is not capturing %used value in the filesystem alert in the subject of the mail alert: Code: #!/bin/bash export DBALIST="abc@xyz.com" df -k /oradata/xyz/archive > dfk.result archive_capacity=`awk -F" " '{ print $5 }' dfk.result|grep -i %| cut -c 1-4` if... (6 Replies)
Discussion started by: harveyclayton
6 Replies

2. Solaris

archive logs mount point space check 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

3. Shell Programming and Scripting

Shell script for Server Mount Point space check

Does anybody have anything I can use to help me out with this one? (4 Replies)
Discussion started by: lbone007
4 Replies

4. Shell Programming and Scripting

Filesystem alert shell script not working!!

Hi All, My below shell script is not capturing %used value in the filesystem alert in the subject of the mail alert: #!/bin/bash export DBALIST="abc@xyz.com" df -k /oradata/xyz/archive > dfk.result archive_capacity=`awk -F" " '{ print $5 }' dfk.result|grep -i %| cut -c 1-4` if ] then... (5 Replies)
Discussion started by: a1_win
5 Replies

5. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

6. Shell Programming and Scripting

Script to check top 5 biggest disk space users

Hi all, I am needing a bash shell script to generate a list of the top 5 users using the most disk space. I am thinking that the du command would be used somehow but I am at a loss. Can anyone help? Thanks! (3 Replies)
Discussion started by: sytemx
3 Replies

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

8. 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

9. Shell Programming and Scripting

Urgent:FileSystem Check Script

This script monitors a FileSystem named /Monthly and send a page; works great but I need to monitor /Daily/All ....Im getting Syntax Error MSG=`df -Ik|awk '$6~/Monthly$/{gsub("%"," "); if ($5>20){print "FS:Monthly filesystem is "$5"%"}}'` if then echo $MSG | mail 2149724690@mobilecomm.net... (1 Reply)
Discussion started by: Openware
1 Replies

10. Shell Programming and Scripting

shell script to mount filesystem

Hi, Gurus: I need your help to finish a script that will mount two file systems automatically when saver is reboot or start. I am working on a new Sun Sparc machine with Solaris 9 on it. This box got two disk. disk one has been partitioned to hold Solaris OS. disk two has been partitioned as... (6 Replies)
Discussion started by: duke0001
6 Replies
Login or Register to Ask a Question