The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > AIX
.
google unix.com



AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Please help - disk space check script maddhadder71 Shell Programming and Scripting 0 05-08-2008 08:16 AM
Urgent:FileSystem Check Script Openware Shell Programming and Scripting 1 04-25-2008 12:32 PM
shell script to mount filesystem duke0001 Shell Programming and Scripting 6 02-15-2007 02:37 PM
Creating my first Shell Script plmahan Shell Programming and Scripting 1 11-21-2004 11:32 PM
help on creating shell script master_6ez Shell Programming and Scripting 1 11-21-2004 09:21 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-06-2006
heprox heprox is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 32
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 (permalink)  
Old 06-07-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Did you search through the forums ?

You should have something like this - Frustrating Disk space script
  #3 (permalink)  
Old 06-07-2006
heprox heprox is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 32
Thanks for the link...for some reason the search on this site is not working for me?
  #4 (permalink)  
Old 06-07-2006
heprox heprox is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 32
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 (permalink)  
Old 06-07-2006
backslash backslash is offline
Registered User
  
 

Join Date: May 2006
Posts: 21
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 (permalink)  
Old 06-07-2006
heprox heprox is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 32
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 (permalink)  
Old 06-07-2006
heprox heprox is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 32
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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0