forked from colin/disk-space-report
Update swap.sh
This commit is contained in:
parent
95c88f7715
commit
2f712d05de
18
swap.sh
18
swap.sh
|
@ -2,17 +2,25 @@
|
|||
|
||||
# Function to create swap file
|
||||
create_swapfile() {
|
||||
# Detect the main disk by finding the partition mounted on root ('/')
|
||||
# Detect the partition mounted on root ('/')
|
||||
mount_point=$(df / | tail -1 | awk '{print $6}')
|
||||
|
||||
# Get available space on the partition in MB
|
||||
# Get available space on the root partition in MB
|
||||
available_space=$(df -BM $mount_point | tail -1 | awk '{print $4}' | sed 's/M//')
|
||||
|
||||
# Calculate 5% of the available space, and ensure it's within the limits (max 30GB)
|
||||
swap_size=$((available_space * 5 / 100 / 1024)) # Convert MB to GB
|
||||
# Calculate 5% of the available space in MB
|
||||
swap_size=$((available_space * 5 / 100)) # 5% of available space in MB
|
||||
|
||||
# Convert swap size from MB to GB
|
||||
swap_size=$((swap_size / 1024)) # Convert MB to GB
|
||||
|
||||
# Set upper limit of 30GB for the swap file
|
||||
if [ $swap_size -gt 30 ]; then
|
||||
swap_size=30
|
||||
elif [ $swap_size -lt 1 ]; then
|
||||
fi
|
||||
|
||||
# Abort if the calculated swap size is less than 1GB
|
||||
if [ $swap_size -lt 1 ]; then
|
||||
echo "Not enough disk space to create a swap file."
|
||||
exit 1
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue