The Schworak Site | Log In | Up One Level

Bash script to mount all drives

Have you ever had your system boot up and found missing mount points that should have initialized? I find this every once in a while when my NFS share can't be reached in a timely manner while logging in.

Now it is easy enough to open a terminal and type "sudo mount -a" and be done with it. But I get a little lazy and would rather just click on a script icon from my GUI.

What I have done is in each empty folder where I attach my mount point, I have a desktop icon that points to a script that will perform the mount for me. Then I just press F5 to refresh the display.

When the drives mount, the script is no longer visible. It is still there in the actual folder, but the mount point takes control so you can't see or even access the script's desktop icon.

Here is the code for the little script. Feel free to modify it as you see fit. This script needs to run from a terminal. If it is not running in a terminal, it will detect that and relaunch itself in the default terminal for the system automatically. This way, the script works equally well from the CLI or GUI environment.


#!/bin/bash

f [ -t 0 ]; then
	echo "Admin password is needed to mount drives"
	echo 
	echo
	sudo echo "Working..."
	sudo mount -a
	current=`pwd`
	cd /
	cd "$corrent"
	echo "Drives mounted. You may need to exit this folder and return to see the changes."
	if [[ "$1" != "" ]]; then
		notify-send "Drives Mounted" "$1"
	fi
else
	x-terminal-emulator -e $0 "Press F5 to refresh the folder you are viewing"
fi

To create the desktop icon that points to this script, be sure our mount points are not mounted. You can use the "umount" command to unmount them if needed.

The details on how to create a desktop icon may be different from one system to the next depending on your interface. You can of course use symbolic links which is the same on every Linux system but they don't give pretty looking icons.

 

Comments

<< jQuery Mobile - Autocomplete Text Input    |    Get FireFox to launch SSH or TELNET links under Linux >>
All content on this site is copyright ©2004-2024 and is not to be reproduced without prior permission.