Help with awk - Disk usage


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with awk - Disk usage
# 1  
Old 08-16-2015
Help with awk - Disk usage

Hi All,

Would appreciate your help as to why the following code not showing the correct output. the issue is on the last else cause. I am trying to report on disk space based on percentage usage. for some reason, it's showing output as OK even thou disk space is 90% !!!! any ideas why? thanks!!

Code:
df -k | awk '
NR > 1 {

        _used=$5; sub(/%/,"",_used);
        if(_used >= 90)
                _status="CRITICAL"
        else if (_used >= 85)
                _status="WARN"
        else if (_used >= 75)
                _status="ATTEN"
        else _status="OK"

}
END { print _status }'




Code:
df -k
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1        9288056 1218896   7597352  95% /
udev              505328       4    505324   1% /dev
tmpfs             205292     312    204980   1% /run
none                5120       0      5120   0% /run/lock
none              513228       0    513228   0% /run/shm

# 2  
Old 08-16-2015
You print the status for the last disk mounted only. Try printing the status for every disk by moving the print from the END section into the "Normal" section right after the if ... else construct.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 08-16-2015
The code is putting a new value in _status on every line and it reports the last _status in the END section. The last line is OK, so that is what gets printed.
This User Gave Thanks to Scrutinizer For This Post:
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 usage monitoring and record the disk used in last 24 hour

HI I am Trying to edit the below code to send email every day with difference of disk utilized in for last 24 hours but instead getting same usage everyday. can you please help me to point out where my calculation is going wrong. Thank you. ================= #!/bin/bash TODAY="at $(date... (0 Replies)
Discussion started by: Mi4304
0 Replies

2. HP-UX

Disk Usage

Hi Experts, glance is showing disk util 100% on of production domain and while collecting sar data using sar -d 5 5, avserv for some of the disks are more than 10 miliseconds. Need your advise on steps that needs to be taken to reduce the disk utilitzation. device %busy avque r+w/s ... (2 Replies)
Discussion started by: sai_2507
2 Replies

3. UNIX for Dummies Questions & Answers

Disk Usage

Hi, I have always felt problems using commands to check disk usage, or I should say I might not be using the commands properly. dfspace and free are 2 most frequent command that I use, but the data that it echoes is not comprehandable atleast to me.:wall::wall::wall::wall::wall: I want... (4 Replies)
Discussion started by: TH3M0Nk
4 Replies

4. Solaris

current CPU usage, memory usage, disk I/O oid(snmp)

Hi, I want to monitor the current cpu usage, monitor usage , disk I/o and network utlization for solaris using SNMP. I want the oids for above tasks. can you please tell me that Thank you (2 Replies)
Discussion started by: S_venkatesh
2 Replies

5. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

6. Shell Programming and Scripting

Disk Usage

Hi, I want to retrieve the directory in the shell script that is using maximum space on the disk.I was using du command but it displays all the directories that are using the space on the disk.How can retrieve the only directory which uses the maximum space on the disk?? Thanks in advance. ... (4 Replies)
Discussion started by: harikamamidala
4 Replies

7. Shell Programming and Scripting

disk usage

Hi ,.. I am working on a script like.... it has to monitor the disk usage (df -H) and if usage is above 95% then it has to return the particular mount point details... i am in confusion to use awk or sed..... regards rrs (1 Reply)
Discussion started by: rrs
1 Replies

8. UNIX for Advanced & Expert Users

disk usage (df vs du)

displaying the disk usage using df and displaying the disk usage using du -sk gives me different results: 1st case: df -k |grep users 2nd case: cd /users; du -sk sometimes this difference is 50 gigabyte!!! do you have any idea about this situation? (8 Replies)
Discussion started by: gfhgfnhhn
8 Replies

9. UNIX for Dummies Questions & Answers

Disk Usage

Im using solaris 8 on a Sunfire 280r. Is there a command to show you how much disk space is being used in gigabytes or megabytes. I dont think theres an option for this using the df command. not for solaris anyway. thanks (3 Replies)
Discussion started by: lewisoco
3 Replies

10. UNIX for Dummies Questions & Answers

disk usage

what are the ways to check the disc usage by users. I mean to say how to find the biggest space consumer. Regards. (4 Replies)
Discussion started by: asutoshch
4 Replies
Login or Register to Ask a Question