Skip to content

Instantly share code, notes, and snippets.

@jeansymolanza
Created October 14, 2024 11:17
Show Gist options
  • Save jeansymolanza/18e9fbc8e4b51c72e15e6b608a779989 to your computer and use it in GitHub Desktop.
Save jeansymolanza/18e9fbc8e4b51c72e15e6b608a779989 to your computer and use it in GitHub Desktop.
# Get the size of the source directory in GB
SRC_SIZE=$(du -sk "$SRC" | awk '{print $1}')
SRC_SIZE_GB=$(echo "scale=2; $SRC_SIZE / 1024 / 1024" | bc)
# Get the available space in the destination in GB
DEST_AVAILABLE=$(df -k "$DEST" | tail -1 | awk '{print $4}')
DEST_AVAILABLE_GB=$(echo "scale=2; $DEST_AVAILABLE / 1024 / 1024" | bc)
# Calculate the required space (source size + 25%) in GB
REQUIRED_SPACE_GB=$(echo "scale=2; $SRC_SIZE_GB + ($SRC_SIZE_GB * 0.25)" | bc)
# Check if the destination has enough space in GB
if (( $(echo "$DEST_AVAILABLE_GB < $REQUIRED_SPACE_GB" | bc -l) )); then
echo "Error: Not enough space in $DEST. Required: $REQUIRED_SPACE_GB GB, Available: $DEST_AVAILABLE_GB GB"
exit 1
fi
# Proceed with the rest of the script if space is sufficient
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment