diff options
author | Patrick Spek <p.spek@tyil.nl> | 2023-05-22 13:15:49 +0200 |
---|---|---|
committer | Patrick Spek <p.spek@tyil.nl> | 2023-05-22 13:15:49 +0200 |
commit | f62d5581db874678630717ff75ce45c6afef2e16 (patch) | |
tree | 28397e4b30468d1a43fb6fc6a236ef626ddea390 | |
parent | c68faef6e653ec2e30aa72a7ac394bcc935917a9 (diff) | |
download | bashtard-f62d5581db874678630717ff75ce45c6afef2e16.tar.gz bashtard-f62d5581db874678630717ff75ce45c6afef2e16.tar.bz2 |
Calculate storage in a POSIX compliant manner
-rw-r--r-- | lib/subcommands/sysinfo.bash | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/subcommands/sysinfo.bash b/lib/subcommands/sysinfo.bash index 336496e..bd6e414 100644 --- a/lib/subcommands/sysinfo.bash +++ b/lib/subcommands/sysinfo.bash @@ -16,6 +16,12 @@ subcommand() { local storage_used local uptime + # Set the variables which are compatible on every POSIX-compliant system + storage_used="$(df | awk '/\d+/ { sum += $3 } END { print sum }')" + storage_free="$(df | awk '/\d+/ { sum += $4 } END { print sum }')" + storage_total=$(( storage_used + storage_free )) + + # And do platform-specific magic case "${BASHTARD_PLATFORM[os]}" in freebsd) load_1="$(uptime | awk -F' *,? *' '{ print $(NF-2) }')" @@ -24,9 +30,6 @@ subcommand() { memory_total=$(( $(sysctl -n hw.physmem) / 1024 )) memory_used=$(( ( $(sysctl -n vm.stats.vm.v_active_count) * $(sysctl -n hw.pagesize) ) / 1024 )) memory_free=$(( memory_total - memory_used)) - storage_used="$(df -c | tail -n1 | awk '{ print $3 }')" - storage_free="$(df -c | tail -n1 | awk '{ print $4 }')" - storage_total=$(( storage_used + storage_free )) uptime=$(( "$(date +%s)" - "$(sysctl -a | awk '/^kern.boottime/ { print substr($5, 0, length($5)-1) }')" )) ;; *) @@ -36,9 +39,6 @@ subcommand() { memory_total="$(awk '/MemTotal/ { print $2 }' < /proc/meminfo)" memory_free="$(awk '/MemAvailable/ { print $2 }' < /proc/meminfo)" memory_used=$(( memory_total - memory_free )) - storage_used="$(df --total | tail -n1 | awk '{ print $3 }')" - storage_free="$(df --total | tail -n1 | awk '{ print $4 }')" - storage_total=$(( storage_used + storage_free )) uptime="$(awk -F. '{ print $1 }' < /proc/uptime)" ;; esac |