Swap

A bash script that will kill the swap file, wait for the swap to flush.
Then bring the swap file back up.

## Folder Structure If you have not done so already, create a new folder called `scripts` in your **~home** folder. This is where all your scripts will go. Inside your `scripts` folder create a new folder called `swap` When done your folders structure should look like this: `/home/[USERNAME]/scripts/swap` ## Set Up The script will need elevated permissions in order to execute with out human intervention. To do so we need to make some changes to the `sudoers` file. Here is how you do it: 1. Open terminal, type: `sudo visudo` to open the file. 2. Add these commands to end of the file. ```bash # # Locations to swap files. # Change [USERNAME] to your own # ALL ALL =(ALL) NOPASSWD: /home/[USERNAME]/scripts/swap.sh ALL ALL =(ALL) NOPASSWD: /home/[USERNAME]/Desktop/swap.sh @includedir /etc/sudoers.d [USERNAME] ALL=(ALL) NOPASSWD: /bin/systemctl restart * [USERNAME] ALL=(ALL) NOPASSWD: /sbin/swapoff [USERNAME] ALL=(ALL) NOPASSWD: /sbin/swapon ``` 3. Exit and Save file. * `CTRL + X` to exit file * `Y` to save file * `ENTER` to write file ## Script ### **`swap.sh`** Get the source code from this repo and save it as `swap.sh` in the **swap** folder created in the previous step. Next we need to change the permissions of this file so that the server can read it. 1. Right click on `swap.sh` then Properties. 2. Click on `Permissions` tab at top. 3. Make sure Owner & Group reflect your `username` with `Read and Write` access to all. 4. Check the `Execute` box to allow executing the file as a program. 5. Close out the window. ### **`swap.desktop`** Now we need to make the `swap.sh` script act like a regular application. Here is how you do it: Get the source code from this repo and save it as `swap.desktop` in the **swap** folder created in the previous step. Next we need to change the permissions of this file so that the server can read it. 1. Right click on `swap.desktop` then Properties. 2. Click on `Permissions` tab at top. 3. Make sure Owner & Group reflect your `username` with `Read and Write` access to all. 4. Check the `Execute` box to allow executing the file as a program. 5. Close out the window. ## Link We now can create a link to this new application and put it anywhere we want. Here is how you do it: 1. Single click on the new **swap** application. It should be activated and indicated by changing to a new color. 2. While **swap** is activated/highlighted, go to `Edit` > `Make Link` You should now see a new icon with an arrow on it. That is your new link that you can then place on your desktop. Thats where mine is. ## Execute If you placed your linked file on the desktop all you have to do is **double click** the icon and the script will will call and execute `swap.sh`. The script will open a terminal and print out each step. While the script is running, (if you have **System Monitor** open) you will see the Swap line spike for a few seconds. Then it will die out. Once its dead the script waits 30 seconds for everything to flush out the system and then the script will enable **swap**. At this point swap should be at zero or super low, basically how it would be after a full system reboot.