From 16637d2b601bef6f99c4ac6b0a02c24bbade6cda Mon Sep 17 00:00:00 2001 From: Sebastian <379651+czarly@users.noreply.github.com> Date: Sun, 24 Mar 2024 15:54:06 +0100 Subject: [PATCH] estimate available space --- disk-space.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 disk-space.sh diff --git a/disk-space.sh b/disk-space.sh new file mode 100755 index 00000000..b553c316 --- /dev/null +++ b/disk-space.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Total disk space in bytes (replace /dev/sda1 with your actual disk) +total_blocks=$(df --output=size /var/lib/docker/volumes | awk 'NR==2') + +# Convert total blocks to bytes +total_disk_space=$((total_blocks * 1024)) + +# Used disk space in bytes +reserved=${1:-50} +used_disk_space=$(( reserved * 1024 * 1024 * 1024 )) + +# Calculate 10% of total disk space +ten_percent=$(( total_disk_space / 10 )) + +# Calculate total available disk space +total_available_space=$(( total_disk_space - used_disk_space - ten_percent )) + +#echo "$total_disk_space" +#echo "$used_disk_space" +#echo "$ten_percent" + +# Convert total available space to human-readable format +#total_available_space_human=$(echo "$total_available_space" | awk '{ split( "B KB MB GB" , v ); s=1; while( $1>1024 ){ $1/=1024; s++ } print int($1) v[s] }') +#total_available_space_human=$(numfmt --to=iec-i --suffix=B "$total_available_space") + +available_space_gb=$(echo "scale=0; $total_available_space / 1073741824" | bc) + +echo "$available_space_gb"