From faac5d22bef83ca670473b8b703b5823b1518b3b Mon Sep 17 00:00:00 2001 From: Lucas Noki Date: Wed, 29 Jan 2020 08:52:50 +0100 Subject: [PATCH] If swap gets deleted entry from /etc/fstab gets also deleted --- modules/swap/module.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/swap/module.py b/modules/swap/module.py index ffedbab..7fb7827 100644 --- a/modules/swap/module.py +++ b/modules/swap/module.py @@ -126,6 +126,15 @@ class SwapModule(AbstractModule): return disable_swapfile = "sudo swapoff {} && ".format(swap_location) + \ "sudo rm {}".format(swap_location) + if self._check_fstab_entry() is True: + with open("/etc/fstab", "r") as fstab_out: + content = fstab_out.readlines() + with open("/etc/fstab", "w") as fstab_in: + content = content[:-1] + for line in content: + fstab_in.write(line) + else: + print("No entry in /etc/fstab!") subprocess.call(disable_swapfile, shell=True) output_swapon = subprocess.check_output(['swapon', '--show']).decode("UTF-8") output_free = subprocess.check_output(['free', '-h']).decode("UTF-8")