From 5aaf360b8d9022d13b6931270fabdd434798c918 Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sat, 20 Oct 2018 22:35:04 -0400 Subject: [PATCH] Updated script to be able to forcefully unmount a drive if an error occurs and the file system is still using a file. --- src/mount_ssh_drive.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/mount_ssh_drive.py b/src/mount_ssh_drive.py index a2fb488..96195fc 100644 --- a/src/mount_ssh_drive.py +++ b/src/mount_ssh_drive.py @@ -66,6 +66,29 @@ def unmount_all_drives(): unmount_drive(file[i + 2]) +def forcefully_unmount_drive(local_mount_point): + """ + Forcefully un-mounts a ssh drive + :param local_mount_point: + :return: + """ + runCode = subprocess.call(["sudo","umount", "-l", local_mount_point]) + if runCode == 0: + print("Un-Mounted " + local_mount_point) + else: + print("Failed to Un-Mount " + local_mount_point) + + +def forcefully_unmount_drives(): + """ + Forcefully un-mounts all drives from the system + :return: + """ + file = module.input_file(MOUNT_FILE) + for i in range(0, len(file), 3): + forcefully_unmount_drive(file[i + 2]) + + def remove_drive(): """ Prompts the user and removes a drive from MOUNT_FILE @@ -137,7 +160,8 @@ def print_mount_menu(): "5) View Drives", "6) Usage", "7) Manage Config", - "8) Exit"]) + "8) Forcefully Un-Mount SSH Drives", + "9) Exit"]) def manage_mount_file(): @@ -146,7 +170,7 @@ def manage_mount_file(): """ print_mount_menu() i = input("Enter Option:") - while i != '8': + while i != '9': if i == '4': add_drive() elif i == '3': @@ -157,6 +181,8 @@ def manage_mount_file(): mount_drives() elif i == '2': unmount_all_drives() + elif i == '8': + forcefully_unmount_drives() elif i == '6': print_usage() elif i == '7':