Linux Bash Help


monstercameron

Well-Known Member
Joined
Oct 19, 2010
Messages
1,001
Website
www.thinkteletronics.com
here is the code any help would be appreciated!

Code:
#if mountpoint -q /dev/sdc1 = 0 then
if /media/toshihdd -q $1;then
	sudo umount -l /dev/sdc1
	echo "unmounting!"
else
	sudo mount.exfat-fuse /dev/sdc1 /media/toshihdd
	echo "mounting"
fi
 
What is
Code:
if /media/toshihdd -q $1
supposed do (especially the "-q" switch, which I'm unfamiliar with)?

I'm assuming that it checks for the existance of the mount point. Then this code has a conceptual problem: "mount" needs the mount point to already exist, so your "else" block will always fail.

If you already have udisks installed (the replacement for HALs storage device management), then you can try something like
this:

Code:
#!/bin/bash

# Quit on error
set -e                                                                                                             

# Replace with partition id you're interested in
my_uuid=E1A5-6FC7

if [ -d "/media/$my_uuid" ]
then
    echo "unmounting"
    udisks --unmount "/dev/disk/by-uuid/$my_uuid"
else
    echo "mounting"
    udisks --mount "/dev/disk/by-uuid/$my_uuid"
fi

echo "done"
 
mount will tell you if something is already mounted or not
Code:
line=`mount | grep toshihdd`
if [ $line -z ]
then
  mount /dev/disk/by-id/<uuid>
else
  umount /media/toshihdd
fi
 
Back
Top