Error while executing disk space script in AIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error while executing disk space script in AIX
# 1  
Old 05-06-2011
Error while executing disk space script in AIX

Code:
#!/bin/ksh for AIX

used=0
mount=${1:-"/mountpoint"}
threshold=${2:-80}
#message="hello"
#SUBJECT="Disk Space Alert"
#EMAIL="xyz@abcinc.com"
used=`df -k $mount | grep % | awk '{print $5}' | sed 's/%//g'`

#echo "Free Space available under \"$mount\" is `expr 100 - $used`%.\n">$message

if [ $used -ge $threshold ]; # at this point am getting error#
then
echo "Space Utilization on \"$mount\" has exceeded the threshhold of ${threshold}%.\n" | mail -s "Disk Space Alert" xyz@abcinc.com

#/bin/mail -s "$SUBJECT" "$EMAIL" < $message
fi


*at if operator it gives "./disk.sh[14]: 180533: unknown test operator" error

can any one help guys ,thanks in advance.

Last edited by Franklin52; 05-07-2011 at 09:19 AM.. Reason: Please use code tags
# 2  
Old 05-06-2011
Without seeing a sample "df -k", I think that the problem is because the column headings include a "%" character. Suggest you have a custom "grep -v" early in the pipeline to get rid of the column headings line.
# 3  
Old 05-06-2011
echo $used and see what is the value you are getting first.

Test should work indeed ok in AIX as well.

Also, check which ksh and use that if it's not /bin/ksh
# 4  
Old 05-06-2011
In fact, please post a sample "df -k" of a filesystem.

On my non-AIX system I'd have to use "df -k -P" to get a line-across format where $5 was the percentage free space.
# 5  
Old 05-16-2011
The problem is that you are not eliminating the heading printed by the df command.

Execution yields:
Code:
df -k /home | grep % | awk '{print $5}' | sed 's/%//g'
Use
1

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

to
Code:
df -k /home | grep % | awk '{print $5}' | sed 's/%//g | tail -1'

and you should be fine.

Last edited by Franklin52; 05-17-2011 at 03:36 AM.. Reason: Please use code tags, thank you
# 6  
Old 05-18-2011
Are you sure about $5 for %Used

On top of the header line being processed as mentioned by Blytsplyk, it looks like you want %Used which is field 4 and not field 5, which is Iused!

Filesystem 1024-blocks Free %Used Iused %Iused Mounted on

So I'm guessing the following might work better:

Code:
used=`df -k $mount | tail -1 | awk '{print $4}' | sed 's/%//g'`


Last edited by sheepish123; 05-18-2011 at 10:31 AM.. Reason: add new info with code tag
# 7  
Old 05-18-2011
Code:
Are you looking for something like this:

>mi_df
============================================================================================================
Filesystem                             Size (MB) Free (MB) %Used   %Iused  Mount
============================================================================================================
/proc                                  0         0         -       -       /proc
/                                      512       382       26      13      Root
/I                                     16384     7380      55      2       /dev/I_lv
/data                                  222208    99457     56      1       /dev/data_lv
/downloads                             49152     6064      88      4       /dev/download_lv
/home                                  8192      4695      43      7       /dev/hd1
/home/sybase                           2048      768       63      5       /dev/sybase_lv
/ms_temp                               4096      4064      1       1       /dev/ms_temp_lv
/nim_export                            65536     8133      88      4       /dev/nim_lv
/opt                                   2048      817       61      13      /dev/hd10opt
/tftpboot                              128       75        41      1       /dev/fslv00
/tmp                                   256       246       4       1       /dev/hd3
/usr                                   5120      2544      51      11      /dev/hd2
/var                                   1024      302       71      18      /dev/hd9var
============================================================================================================

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Disk space script

i have 3 servers and i am checking for the disk space of a specific mount-point, should not be more than 85 % considering example as below server1 mountpoint_1 has 70% diskutilization server2 mountpoint_1 has 80% diskutilization server3 mountpoint_1 has 7% diskutilization now when it... (6 Replies)
Discussion started by: abhaydas
6 Replies

2. Red Hat

Subject: value out of range error on a disk with free 40 GB space

Hi, I installed RHEL 6.0 OS on vmware with CREATE CUSTOM LAYOUT option. And I gave the space to different mount points as mentioned below: / 15360MB /boot 200MB /tmp 3072 MB swap 1024 MB fdisk -cul command shows the disk size as 64.4 GB. But when I try to create partion of 10 GB with... (1 Reply)
Discussion started by: GAURAV SRIVASTA
1 Replies

3. AIX

Error while executing command in aix box

Hi Folks I get the below error in my aix box. Im not sure if this is an AIX issue or a TWS issue. Please advice me cbspsdb01:/opt/TWS/bin # ./conman status exec(): 0509-036 Cannot load program ./conman because of the following errors: 0509-150 Dependent module... (6 Replies)
Discussion started by: newtoaixos
6 Replies

4. Shell Programming and Scripting

disk space utilization script

Hi, I wrote the following script for monitoring disk space and inform the concerned team accordingly. But script gives me below error syntax error at line 70 : `<' unmatched #!/bin/ksh . /home/scr/.profile . /home/scr/.infa_env # Get the list of Integration Services ... (6 Replies)
Discussion started by: svajhala
6 Replies

5. AIX

Determine disk space in AIX

Hi I need to extend a FS in AIX but Im not sure on how to calculate the free space Please advise if my math is correct: -------PP SIZE: 64 megabyte(s) --------TOTAL PPs: 1086 (69504 megabytes) so the total size of volume is 64 * 1086 = 69504 MB (695GB) Free PP is-- FREE... (4 Replies)
Discussion started by: hedkandi
4 Replies

6. AIX

AIX Free disk space

Hello, I would like to free some space to install gcc with is about 50M large, and I have no free space on my system. What can I delete? Filesystem 1024-blocks Used Free %Used Iused Ifree %Iused Mounted on /dev/hd4 262144 145436 116708 56% 7981 ... (10 Replies)
Discussion started by: aixn00b
10 Replies

7. Shell Programming and Scripting

Script for Disk space

:( Hi All, i have 4 linux server for which i want set up script to monitor the disk space ... here my problem is i want the output like graph... also it should reflect in monitor ...as non stop process.. can any one suggest me any way where i can implement the script? ... (3 Replies)
Discussion started by: Shahul
3 Replies

8. Shell Programming and Scripting

Disk space script

Hi all, Can any one help me in making a disk space script in solaris 8/9 for instance i only want to get those partitions whose diskspace has exceed 70%. Any volunteer? Cheers! BR/asad (8 Replies)
Discussion started by: asadlone
8 Replies

9. AIX

Disk space error.

Dear All, I am working on AIX 5.2, and I have allocated 3072M disk space to /home filesystem. Now system has no free space at /home filesystem. But when I checked data on /home, I have only 900M data. Please if anybody can tell me about this difference and how this can be resolved. Thank You.... (9 Replies)
Discussion started by: system-admin
9 Replies

10. UNIX for Dummies Questions & Answers

[AIX] executing script

Hello! I need to run a script from the root user as the other user. I know that I can issue the following command: su - user_name -c "/path_to_script/script_name.sh" But there is a small problem with the above command. I must export a environment variable before I run the script. In the... (1 Reply)
Discussion started by: piooooter
1 Replies
Login or Register to Ask a Question