Help with script to display space usage


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with script to display space usage
# 1  
Old 10-13-2015
Help with script to display space usage

Hi all,

I am looking for help with a script for displaying the space available from a df - h command for / (root).
The problem is: If it is below 700 MB I have jobs that are failing... Is there a way I can do a calculation? If it above 700 MB it is good, if it is below 700 MB it will fail. Any help would be appreciated.

thanks,
Gartie
# 2  
Old 10-13-2015
How far have you come?

---------- Post updated at 18:25 ---------- Previous update was at 17:59 ----------

Howsoever, try
Code:
df --output=avail / | { read AV; read AV; [ $AV -gt 700000 ] && echo good || echo bad; }

This one asumes that exactly 700 MB is "bad".
This User Gave Thanks to RudiC For This Post:
# 3  
Old 10-13-2015
how far have I come.

Hi Rudic,

I have not gone far at all... I have just started on the script, and it is failing.
I am trying to get the script to read that anything in / below 700 MB is going to fail..

thanks

gartie
# 4  
Old 10-13-2015
Code:
df  >temp
while read a b c d e f
do
if [ "$f" = "/" ]
then
    if [ $d -gt 704000 ]
    then
    echo "OK"
    fi
fi
done <temp

It's easier to not use the -h option on df, just remember that the free space is in 1k blocks.
This User Gave Thanks to jgt For This Post:
# 5  
Old 10-13-2015
Quote:
Originally Posted by jgt
Code:
df  >temp
while read a b c d e f
do
if [ "$f" = "/" ]
then
    if [ $d -gt 704000 ]
    then
    echo "OK"
    fi
fi
done <temp

It's easier to not use the -h option on df, just remember that the free space is in 1k blocks.
The default unit on POSIX conforming systems is 512-byte blocks; not 1k. And, you can make it a little bit faster by just processing root. If you change the 1st line of the script above to:
Code:
df -k / > temp

and the rest of the script should be OK.
This User Gave Thanks to Don Cragun For This Post:
# 6  
Old 10-13-2015
df -kP is most portable IMHO.?
Code:
df -kP / |
{
read header
read a b c d e f
if [ $d -gt 704000 ]
then
  echo "OK"
else
  echo "NOT ok"
fi
}

This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl Script to find the disk usage and to delete the files which is consuming more space

Hi All, I have written a script to check the file system usage and to delete the files which is consuming more space.Please check whether the script is corrcet #Script Starts here #!/usr/local/bin/perl #Program to find the disk space and to delete the older files #Checks the type of OS... (8 Replies)
Discussion started by: arunkarthick
8 Replies

2. AIX

FS space usage

Hello. I have a clean-up script that deletes > 5days old files on /archive/idocs directory. This script runs twice a week, Tuesday and Friday. This creates a log file that shows the current space usage before and after the files were deleted from the directory. On Feb 3, the script ran and... (2 Replies)
Discussion started by: udelalv
2 Replies

3. HP-UX

Space usage in MB or GB

hi, In HP unix, how can check the space usage in Mb bdf will give me the output in Bytes i guess. Also, how can i check the directory size in hp unix. Thx (4 Replies)
Discussion started by: bang_dba
4 Replies

4. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

5. Shell Programming and Scripting

script to monitor disk space usage

Some times my disk space is used upto 100% due to the application logs . So this script is to monitor the disk space usage and wall message to the users about the disk space usage if it exceeds the limit set in the script. Here for example the limit is set to 80%. This job is added in cron to... (2 Replies)
Discussion started by: amitranjansahu
2 Replies

6. Shell Programming and Scripting

Shell script delete log files from folder & subfolders on space usage

Hi, I am trying to write a shell script to delete logs generate by db when space in the folder reaches 70%. i am getting space values from db, find the files at OS and remove them by using a cron job runs every 5minutes. I have to keep the latest 5 files at any time, my problem is that log files... (3 Replies)
Discussion started by: saha
3 Replies

7. Shell Programming and Scripting

shell script to send email with usage of space in the directory as description :

shell script to send email with usage of space in the directory as description : Please any one help me in writing a script to send email with usage of space in the directory as description . (3 Replies)
Discussion started by: sakthifire
3 Replies

8. UNIX for Dummies Questions & Answers

Want display a line with space in file by unix script

HI , I am having a file as -----------------a.out------------------- Hi I am unix developer using hp unix this is a test --------------------------------------- i need to read each line by a unix script of the file and to print in console with the space in the line as ... (9 Replies)
Discussion started by: arunkumar_mca
9 Replies

9. Filesystems, Disks and Memory

Inconsistent memory usage display

When i was trying to store a file of size 743 MB into a directory i got a msg. that the disk is full. But when i used the df -k . command on that directory it showed only 40% in usage and the disk had more than enough memory for the file. When i checked the syslog i found that at that instant of... (2 Replies)
Discussion started by: spdas
2 Replies

10. Filesystems, Disks and Memory

How do you display summary of disk usage?

I am trying to create a command string that makes use of the du or df utilities to show block count in kilobytes (1024 bytes) instead of multiples of 512 bytes, any suggestions? Thanks..... (3 Replies)
Discussion started by: klannon
3 Replies
Login or Register to Ask a Question