Web hosting servers - /dev/hda1 1190014 664661 463867 59% / The output
/dev/hda1 1190014 664661 463867 59% / The output consists of a header line and information about the hard drive or hard drive partition that the directory or file you specified is located on. In this output, the amount of free space is stored in the fourth column. Your function uses awk to get at this value. ################################################ # Name: getSpaceFree # Desc: output the space avail for a directory # Args: $1 -> The directory to check ################################################ getSpaceFree() { if [ $# -lt 1 ] ; then printERROR “Insufficient Arguments.” return 1 fi df -k “$1″ | awk ‘NR != 1 { print $4 ; }’ } As you can see, the function is quite simple. It first checks to see whether it was given an argument. If no argument was given, it displays an error message and returns. Otherwise, it runs the df -k command and displays the number stored in the fourth column. You use the awk expression NR != 1 to skip the first line that contains the header. For more information on awk, please look at Chapter 17, “Filtering Text with awk.” As an example of using this function, the command getSpaceFree /usr/local displays the following value on my system: 2335788 The number returned is in kilobytes, which means I have about 2.3GB free in the directory /usr/local. Frequently you might want to compare the output of this function to some value. For example, the following if statement checks to see whether more than 20,000KB are available in the directory /usr/local: if [ ” getSpaceFree /usr/local ” -gt 20000 ] ; then echo “Enough space” fi Determining Space Used
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.