You are not logged in.
this thread https://bbs.archlinux.org/viewtopic.php?id=185712 gave me an idea and teach me.
I created a script to mount/umount usb. Save it in user's home dir, do
chmod
and click on it as a toggle button to mount/umount usb.
It only work for one usb plugged in. Please suggest me to get it work for two or more.
#! /bin/bash
# mr = mounted result
# ur = umounted result
# er = empty result
# cm = check mountpoint
# cup = check usb is plugged in
# usb = usb device (Example... /dev/sdb1)
cm=$(mountpoint /home/username/tmp)
cup=$(lsblk | grep "sd[b-z]1")
usb=$(ls /dev/sd[b-z]1)
er=""
ur="/home/username/tmp is not a mountpoint"
mr="/home/username/tmp is a mountpoint"
if [ "$cm" == "$ur" ] && [ "$cup" != "$er" ]; then
echo "password" | sudo -S mount -o uid=username,gid=users $usb /home/username/tmp
elif [ "$cm" == "$mr" ] && [ "$cup" != "$er" ]; then
echo "password" | sudo -S umount /home/username/tmp
else
exit
fi
Amazing !
Offline
At the first I thought you may use a udev rule to automate your task. (see /usr/lib/udev/rules.d/80-udisks.rules for guidelines)
As you may know udev can call any kind of executable, hence one of yours too.
Last edited by TheSaint (2014-12-24 02:14:16)
do it good first, it will be faster than do it twice the saint
Offline
You might want to check out the bashmount package in the AUR. If you are looking for a quick solution to mount removable media that may be it.
If you want to improve your script, for instance your multiple device question, I found the bashmount code to be very well laid out and well commented. I would suggest using that as a model.
Offline
There are a number of issues with your script; the reason you can't mount more than one device is that if "${usb[@]}" is populated by more than one drive, you need to iterate over the array to mount them.
Other issues that you should consider are:
your variable names are brief to the point of unintelligble: it is very hard to follow what is going on with "$mr", "$ur", "$cr" etc
don't put messages in variables; `printf` them
relatedly; check exit status, not strings: `$?`
if you are using bash; see What is the difference between [ and [[?
rather than `echo`ing your password (see 3), add the script to `sudoers`
Hope (some of) that helps.
Offline
thanks all for advices and links. they are helpful to learn bash.
Amazing !
Offline