#!/bin/bash -e
 # Set default variable values
 : ${SWAP_SIZE_MEGABYTES:=1024}
 : ${SWAP_FILE_LOCATION:=/var/swap.space}
 if (( $SWAP_SIZE_MEGABYTES <= 0 )); then
 echo 'No swap size provided, exiting.'
 exit 1
 elif [ -e "$SWAP_FILE_LOCATION" ]; then
 echo "$SWAP_FILE_LOCATION" already exists, skipping.
 fi
 if ! swapon -s | grep -qF "$SWAP_FILE_LOCATION"; then
 echo Creating "$SWAP_FILE_LOCATION", "$SWAP_SIZE_MEGABYTES"MB.
 dd if=/dev/zero of="$SWAP_FILE_LOCATION" bs=1024 count=$(($SWAP_SIZE_MEGABYTES*1024))
 mkswap "$SWAP_FILE_LOCATION"
 swapon "$SWAP_FILE_LOCATION"
 echo 'Swap status:'
 swapon -s
 else
 echo Swap "$SWAP_FILE_LOCATION" file already on.
 fi
 echo 'Done.'
Share
Disqus Comments Loading...

Recent Posts

Run Systemd Script Before System Shutdown

For the sheer hell of it, a few weeks ago I wanted to see if I could properly and successfully… Read More

April 20, 2019 10:14 am 10:14

Learn Systemctl Usage to Manage Systemd Service in Linux

Systemd is new service manager for Linux. It's a replacement for all previous init systems (SysV/SysVinit & Ubuntu's Upstart) and… Read More

April 20, 2019 7:55 am 07:55

Force Delete Windows Server DHCP Failover Relationship

If you've found yourself here then chances are you messed up one of your domain controllers or at least one… Read More

April 20, 2019 5:54 am 05:54

Determine Your Upstream DNS Resolver

The following one-liner Bash will output your upstream DNS resolver. You will need to install the whois package for this… Read More

April 7, 2019 11:00 am 11:00

Android Connect to Microsoft SSTP VPN Free

I've finally found a VPN client that will allow connecting from an Android phone to a Microsoft Windows Server 2008-2019… Read More

April 2, 2019 4:52 pm 16:52

VMWare vSphere 6.7 ESXTOP Output Garbled

If your VMWare vSphere 6.x environment command output of esxtop looks like a bunch of garbled gibberish (it's actually CSV… Read More

February 28, 2019 7:39 pm 19:39