Try to use awk or sed to get available disk space

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Try to use awk or sed to get available disk space
# 1  
Old 03-21-2014
Try to use awk or sed to get available disk space

Guys this is my 1st post so please excuse if i am asking something already answered

I am trying to write a script to send an alert whenever any of my servers runs low on disk space, i am getting the following output

9 Dir(s) 6,611,517,440 bytes free

I need to just get 6,611,517,440 from this string, see if this value is less than 2gb and if it is send out an email.

I need help with getting the number and comparing it with 2GB.

Any help would be appreciated.
# 2  
Old 03-21-2014
... | awk '{ gsub(/,/,"",$2); if($2 < 2000000000) print $2 }'

# 3  
Old 03-21-2014
A bit long-winded, but here's an approach:


# check that something was piped to the script
# by reading the actual pipe descriptor
if [ $(readlink /proc/$$/fd/0 | grep -c "^pipe:") == 1 ]
    # store the value that was piped to the script
    input=$(cat /proc/$$/fd/0)

    # extract the bytes and remove the commas
    sz=$(echo $input | awk '{gsub(/,/,"",$3); print $3}')

    # convert the bytes to gigabytes and compare if greater
    # than 2GBs
    getsize=$(echo "scale=0;${sz}/1024/1024/1024"|bc)
    if [ $getsize -gt 2 ]
        echo "Current size is greater than the 2GB threshold."
        echo "Current size is within range."
    echo "Nothing on the pipeline."
    exit 1

# done
exit 0

echo "9 Dir(s) 6,611,517,440 bytes free" | ./
Current size is greater than the 2GB threshold.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk -sed help : forth . to convert to "space"

Hi Experts, Good day, I am looking for the 6th fields 4th dot (.) to convert into a space in the output. file: tcp 0 0 2900 1 ESTABLISHED tcp 0 0 2900 1 ESTABLISHED tcp 0 ... (11 Replies)
Discussion started by: rveri
11 Replies

2. Shell Programming and Scripting

Sed/awk : to grep only required pattern disk

Hi Experts, Need help with the following: Desired output: Only want to get the output marked in green. The file: --- Physical volumes --- PV Name /dev/disk/disk4704 PV Status available Total PE 6399 Free PE ... (3 Replies)
Discussion started by: rveri
3 Replies

3. UNIX for Advanced & Expert Users

Need to remove leading space from awk statement space from calculation

I created a awk state to calculate the number of success however when the query runs it has a leading zero. Any ideas on how to remove the leading zero from the calculation? Here is my query: cat myfile.log | grep | awk '{print $2,$3,$7,$11,$15,$19,$23,$27,$31,$35($19/$15*100)}' 02:00:00... (1 Reply)
Discussion started by: bizomb
1 Replies

4. Shell Programming and Scripting

Help awk/sed: putting a space after numbers:to separate number and characters.

Hi Experts, How to sepearate the list digit with letters : with a space from where the letters begins, or other words from where the digits ended. file 52087mo(enbatl) 52049mo(enbatl) 52085mo(enbatl) 25051mo(enbatl) The output should be looks like: 52087 mo(enbatl) 52049... (10 Replies)
Discussion started by: rveri
10 Replies

5. Shell Programming and Scripting

Awk/sed - add space between dot and letter

I need to change . into . so that e.g. A.Jbecomes A. JI have tried sed 's/\./\.\ /g' but that didn't work. (9 Replies)
Discussion started by: locoroco
9 Replies

6. Shell Programming and Scripting

awk or sed command to print specific string between word and blank space

My source is on each line - - "GET /disp0201.php?poc=4060&roc=1&ps=R&ooc=13&mjv=6&mov=5&rel=5&bod=155&oxi=2&omj=5&ozn=1&dav=20&cd=&daz=&drc=&mo=&sid=&lang=EN&loc=JPN HTTP/1.1" 302 - "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR... (5 Replies)
Discussion started by: elamurugu
5 Replies

7. Red Hat

disk space

when i check /export directory of my machine gets filled up (85%) i removed some old logs. but after cleaning df -k command still shows that /export is still 85% full. Is there a way to force df to reflect actual free space without rebooting? My machine is a production one and can't... (8 Replies)
Discussion started by: aboorkuma
8 Replies

8. HP-UX

Disk Space

Hi Experts. I had 100% disk full , even though i have removed 2 GB space still dbf command shows 100%. How to rectify that. Appreciate your prompt help. Thanks (1 Reply)
Discussion started by: test10002
1 Replies

9. UNIX for Dummies Questions & Answers

available disk space on disk device???

Hello, Can someone please tell me which command to use to determine the available disk space on a given disk device? I have to write a shell script that compresses files and stores them in a specific location but I am not sure how "conservative" I should be? Thanks in advance! Al. (4 Replies)
Discussion started by: alan
4 Replies

10. Filesystems, Disks and Memory

Disk space

Can someone tell me how to determine how much disk space has been allocated to me and how much of it I am using? Thanks in advance. (1 Reply)
Discussion started by: jxh461
1 Replies
Login or Register to Ask a Question