Creating a shell script to check filesystem space


 
Thread Tools Search this Thread
Operating Systems AIX Creating a shell script to check filesystem space
# 1  
Old 06-06-2006
Question Creating a shell script to check filesystem space

I need to create a simple shell script to check filesystems space in a file system called "/arch_nb" then based on the percentage use either run another script or exit.

I was thinking of something simple along the lines of:

df -k | then some action to pipe for percentage used

...place all of this in a logic "if/then" clause?

Anyone have something like that already?
# 2  
Old 06-07-2006
Did you search through the forums ?

You should have something like this - https://www.unix.com/shell-programming-and-scripting/27923-frustrating-disk-space-script.html
# 3  
Old 06-07-2006
Thanks for the link...for some reason the search on this site is not working for me?
# 4  
Old 06-07-2006
Question

Interstingly when I try run the following:

Code:
#!/bin/ksh
 
used_space=0
mount_point=${1:-"/tmp"}
threshold=${2:-10}
 
used_space=`df -k $mount_point | grep % | awk {'print $5'} | sed 's/%//g'`
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

I get:

Code:
expr: 0402-046 A specified operator requires numeric parameters.
Free Space available under "/tmp" is %.
 
run_rman_script_fs_check[12]: 830: 0403-012 A test command parameter is not valid.

...it looks like my version of AIX (5.2) doesn't like something about the expression "`expr 100 - $used_space`%.\n"?
# 5  
Old 06-07-2006
There's probably something wrong with setting the used space variable in from the df command.

It's good practise to quote your test parameters in double quotes so that if they are not set the test expression will not return with an error and treat the value as null.

I'm not near an AIX box at the moment but suggest you run the following from the command prompt to see what is returned:

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

Ah just spotted what the problem might be. Try this (note the single quotes position)

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

Hope that helps.
\
# 6  
Old 06-07-2006
Question

I changed the script to:

Code:
#!/bin/ksh
 
used_space=0
mount_point=${1:-"/tmp"}
threshold=${2:-10}
 
used_space='df -k $mount_point | grep % | awk '{print $5}' | sed 's/%//g''
print "Free Space available under \"$mount_point\" is `$used_space`%.\n"

...but I still get:

Code:
run_rman_script_fs_check[7]: } | sed s/%//g:  not found.
run_rman_script_fs_check[8]: 0:  not found.
Free Space available under "/tmp" is %.

I tried changing the line:

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

...as well but with worse results?
# 7  
Old 06-07-2006
Question

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

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