Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #-------------------------------------------------------------------------------
- #Created by Vincent mailto: ezarchproject[at]gmail[dot]com
- # This was inspired by the dfspace that was found on the net
- # and is rewritten.
- #-------------------------------------------------------------------------------
- #This program is free software: you can redistribute it and/or modify
- #it under the terms of the GNU General Public License as published by
- #the Free Software Foundation, either version 3 of the License, or
- #(at your option) any later version.
- #
- #This program is distributed in the hope that it will be useful,
- #but WITHOUT ANY WARRANTY; without even the implied warranty of
- #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- #GNU General Public License for more details.
- #
- #You should have received a copy of the GNU General Public License
- #along with this program. If not, see <http://www.gnu.org/licenses/>.
- #-------------------------------------------------------------------------------
- # Explaination of the Script:
- #
- # This script is designed for GNU/Linux as this came from another script
- # found on the internet. The idea of this came from UNIX dfspace which was
- # on various commercial UNIX systems including AT&T and SCO.
- #
- OS=`uname`
- #Program Locations
- df=${DF:-'/bin/df'}
- AWK=/usr/bin/awk
- # Options to DF
- DF_FS_OPTS="-t ext2 -t ext3 -t ext4" # Default Filesystems
- DF_XTRA_OPTS="-P" # Additional Opts -P is posix
- TOTAL_OPTS="-k $DF_FS_OPTS $DF_XTRA_OPTS"
- echo
- $df -k $TOTAL_OPTS | $AWK -v os=$OS '
- # Calculations
- BEGIN {
- printf("-------------------------------------------\n ****** Space on the filesystems ***** \n-------------------------------------------\n\n")
- Blksize=1024;
- Mbyte = 1024 * 1024;
- MbyteBlocks = Blksize / Mbyte;
- Gbyte = Mbyte * 1024;
- GbyteBlocks = Blksize / Gbyte;
- Tbyte = Gbyte * 1024;
- TbyteBlocks = Blksize / Tbyte;
- totalFilesystems = 0;
- }
- NR == 1 {}
- NR > 1 {
- fileSystem=$NF;
- free=$4;
- alloc=$2;
- split($2,allocptr," "); alloc = allocptr[1]+0
- if (fileSystem !~ /^\/proc/ && fileSystem !~ /^\/dev\/fd/)
- {
- totalFilesystems++;
- if (alloc == 0) alloc = 1; # avoid division by zero
- # In all cases, the "- 0.005" forces rounding down.
- if ((free * TbyteBlocks) >= 1)
- {
- totalFree = (free * TbyteBlocks) - 0.005;
- totalFreeLabel = "TB";
- }
- else if ((free * GbyteBlocks) >= 1)
- {
- totalFree = (free * GbyteBlocks) - 0.005;
- totalFreeLabel = "GB";
- }
- else
- {
- totalFree = (free * MbyteBlocks) - 0.005;
- totalFreeLabel = "MB";
- }
- if ((alloc * TbyteBlocks) >= 1)
- {
- totalAlloc = (alloc * TbyteBlocks) - 0.005;
- totalAllocLabel = "TB";
- }
- else if ((alloc * GbyteBlocks) >= 1)
- {
- totalAlloc = (alloc * GbyteBlocks) - 0.005;
- totalAllocLabel = "GB";
- }
- else
- {
- totalAlloc = (alloc * MbyteBlocks) - 0.005;
- totalAllocLabel = "MB";
- }
- percentFree = free * 100 / alloc
- if (totalFree < 0) totalFree=0
- if (totalAlloc < 0) totalAlloc=0
- if (len (fileSystem > 16))
- fileSystem = substr (fileSystem, 1, 16);
- printf ("%-20s Disk space: %#9.2f %s of %#9.2f %s available (%#5.2f%%)\n", fileSystem, totalFree, totalFreeLabel, totalAlloc, totalAllocLabel, percentFree)
- Cumfree += free;
- Cumalloc += alloc;
- }
- }
- END {
- if ((Cumalloc > 0) && (totalFilesystems > 1))
- {
- CumPct=Cumfree * 100 / Cumalloc
- if ((Cumfree * TbyteBlocks) >= 1)
- {
- totalFree = (Cumfree * TbyteBlocks) - 0.005;
- totalFreeLabel = "TB";
- }
- else if ((Cumfree * GbyteBlocks) >= 1)
- {
- totalFree = (Cumfree * GbyteBlocks) - 0.005;
- totalFreeLabel = "GB";
- }
- else
- {
- totalFree = (Cumfree * MbyteBlocks) - 0.005;
- totalFreeLabel = "MB";
- }
- if ((Cumalloc * TbyteBlocks) >= 1)
- {
- totalAlloc = (Cumalloc * TbyteBlocks) - 0.005;
- totalAllocLabel = "TB";
- }
- else if ((Cumalloc * GbyteBlocks) >= 1)
- {
- totalAlloc = (Cumalloc * GbyteBlocks) - 0.005;
- totalAllocLabel = "GB";
- }
- else
- {
- totalAlloc = (Cumalloc * MbyteBlocks) - 0.005;
- totalAllocLabel = "MB";
- }
- printf ("\n%10s:%14s%#9.2f %s of %#9.2f %s available (%#5.2f%%)\n\n", "Overall Disk Space", " ", totalFree, totalFreeLabel, totalAlloc, totalAllocLabel, CumPct)
- }
- }'
- echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement