![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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? |
|
|||||
|
Did you search through the forums ?
You should have something like this - Frustrating Disk space script |
|
||||
|
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
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. |
|
||||
|
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. \ |
|
||||
|
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"
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 %. Code:
used_space="df -k $mount_point | grep % | awk '{print $5}' | sed 's/%//g'"
|
|
||||
|
When I run the command:
Code:
df -k $mount_point | grep % | awk {'print $5'} | sed 's/%//g'
Code:
x-4-1-test# df -k /tmp | grep % | awk {'print $5'} | sed 's/%//g'
Iused
774
Code:
df -k /tmp | grep % | awk '{print $5}' | sed 's/%//g'
Code:
expr 100 - $used_space`%.\n |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|