Advertisement
ezarchproject

dfspace-ez-arch.sh

Dec 25th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. #!/bin/sh
  2. #-------------------------------------------------------------------------------
  3. #Created by Vincent mailto: ezarchproject[at]gmail[dot]com
  4. # This was inspired by the dfspace that was found on the net
  5. # and is rewritten.
  6. #-------------------------------------------------------------------------------
  7. #This program is free software: you can redistribute it and/or modify
  8. #it under the terms of the GNU General Public License as published by
  9. #the Free Software Foundation, either version 3 of the License, or
  10. #(at your option) any later version.
  11. #
  12. #This program is distributed in the hope that it will be useful,
  13. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. #GNU General Public License for more details.
  16. #
  17. #You should have received a copy of the GNU General Public License
  18. #along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #-------------------------------------------------------------------------------
  20. # Explaination of the Script:
  21. #
  22. # This script is designed for GNU/Linux as this came from another script
  23. # found on the internet. The idea of this came from UNIX dfspace which was
  24. # on various commercial UNIX systems including AT&T and SCO.
  25. #
  26.  
  27.  
  28. OS=`uname`
  29.  
  30. #Program Locations
  31.  
  32. df=${DF:-'/bin/df'}
  33. AWK=/usr/bin/awk
  34.  
  35. # Options to DF
  36.  
  37. DF_FS_OPTS="-t ext2 -t ext3 -t ext4" # Default Filesystems
  38. DF_XTRA_OPTS="-P" # Additional Opts -P is posix
  39.  
  40. TOTAL_OPTS="-k $DF_FS_OPTS $DF_XTRA_OPTS"
  41. echo
  42. $df -k $TOTAL_OPTS | $AWK -v os=$OS '
  43.  
  44. # Calculations
  45. BEGIN {
  46. printf("-------------------------------------------\n ****** Space on the filesystems ***** \n-------------------------------------------\n\n")
  47. Blksize=1024;
  48. Mbyte = 1024 * 1024;
  49. MbyteBlocks = Blksize / Mbyte;
  50. Gbyte = Mbyte * 1024;
  51. GbyteBlocks = Blksize / Gbyte;
  52. Tbyte = Gbyte * 1024;
  53. TbyteBlocks = Blksize / Tbyte;
  54. totalFilesystems = 0;
  55. }
  56. NR == 1 {}
  57. NR > 1 {
  58. fileSystem=$NF;
  59. free=$4;
  60. alloc=$2;
  61. split($2,allocptr," "); alloc = allocptr[1]+0
  62. if (fileSystem !~ /^\/proc/ && fileSystem !~ /^\/dev\/fd/)
  63. {
  64. totalFilesystems++;
  65. if (alloc == 0) alloc = 1; # avoid division by zero
  66. # In all cases, the "- 0.005" forces rounding down.
  67. if ((free * TbyteBlocks) >= 1)
  68. {
  69. totalFree = (free * TbyteBlocks) - 0.005;
  70. totalFreeLabel = "TB";
  71. }
  72. else if ((free * GbyteBlocks) >= 1)
  73. {
  74. totalFree = (free * GbyteBlocks) - 0.005;
  75. totalFreeLabel = "GB";
  76. }
  77. else
  78. {
  79. totalFree = (free * MbyteBlocks) - 0.005;
  80. totalFreeLabel = "MB";
  81. }
  82. if ((alloc * TbyteBlocks) >= 1)
  83. {
  84. totalAlloc = (alloc * TbyteBlocks) - 0.005;
  85. totalAllocLabel = "TB";
  86. }
  87. else if ((alloc * GbyteBlocks) >= 1)
  88. {
  89. totalAlloc = (alloc * GbyteBlocks) - 0.005;
  90. totalAllocLabel = "GB";
  91. }
  92. else
  93. {
  94. totalAlloc = (alloc * MbyteBlocks) - 0.005;
  95. totalAllocLabel = "MB";
  96. }
  97. percentFree = free * 100 / alloc
  98. if (totalFree < 0) totalFree=0
  99. if (totalAlloc < 0) totalAlloc=0
  100.  
  101. if (len (fileSystem > 16))
  102. fileSystem = substr (fileSystem, 1, 16);
  103. printf ("%-20s Disk space: %#9.2f %s of %#9.2f %s available (%#5.2f%%)\n", fileSystem, totalFree, totalFreeLabel, totalAlloc, totalAllocLabel, percentFree)
  104. Cumfree += free;
  105. Cumalloc += alloc;
  106. }
  107. }
  108. END {
  109. if ((Cumalloc > 0) && (totalFilesystems > 1))
  110. {
  111. CumPct=Cumfree * 100 / Cumalloc
  112. if ((Cumfree * TbyteBlocks) >= 1)
  113. {
  114. totalFree = (Cumfree * TbyteBlocks) - 0.005;
  115. totalFreeLabel = "TB";
  116. }
  117. else if ((Cumfree * GbyteBlocks) >= 1)
  118. {
  119. totalFree = (Cumfree * GbyteBlocks) - 0.005;
  120. totalFreeLabel = "GB";
  121. }
  122. else
  123. {
  124. totalFree = (Cumfree * MbyteBlocks) - 0.005;
  125. totalFreeLabel = "MB";
  126. }
  127. if ((Cumalloc * TbyteBlocks) >= 1)
  128. {
  129. totalAlloc = (Cumalloc * TbyteBlocks) - 0.005;
  130. totalAllocLabel = "TB";
  131. }
  132. else if ((Cumalloc * GbyteBlocks) >= 1)
  133. {
  134. totalAlloc = (Cumalloc * GbyteBlocks) - 0.005;
  135. totalAllocLabel = "GB";
  136. }
  137. else
  138. {
  139. totalAlloc = (Cumalloc * MbyteBlocks) - 0.005;
  140. totalAllocLabel = "MB";
  141. }
  142. printf ("\n%10s:%14s%#9.2f %s of %#9.2f %s available (%#5.2f%%)\n\n", "Overall Disk Space", " ", totalFree, totalFreeLabel, totalAlloc, totalAllocLabel, CumPct)
  143. }
  144. }'
  145. echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement