Hi everybody. I'm learning to write some shell scripts to work with the system. Now I'm on a script to mount a device by its full path.
Here is what I've done so far:
PARTITION=$1 # Get device path by 1st parameter
PTYPE=`blkid $PARTITION -o value -s TYPE 2>&1` #Get partition type
echo "Partition: $PARTITION, type: $PTYPE"
if [ $PTYPE ] ; then # Mountable partition
MOUNTNAME=`echo $PARTITION | egrep -o [h,s]d.[0-9]+`
if [ $PTYPE=="ntfs" ] ; then # If this is an ntfs, apply a special option
mkdir -p $MOUNTPOINT
echo "Mount options for $PARTITION: $MOUNTOPS"
mount $MOUNTOPS $PARTITION $MOUNTPOINT
echo $MOUNTPOINT" mounted."
else # blkid returned nothing, usually this is a "container" partition and not mountable
echo "Unknown type"
But when it comes to the type check, the condition on ntfs type is always met, which means that the mount options is always "-t ntfs-3g", regardless of what type the partition is.
Here the output of the command on an ext3 partition:
# mount-any /dev/hda8
Partition: /dev/hda8, type: ext3
Mount options for /dev/hda8: -t ntfs-3g
NTFS signature is missing.
Failed to mount '/dev/hda8': Invalid argument
The device '/dev/hda8' doesn't have a valid NTFS.
Maybe you selected the wrong device? Or the whole disk instead of a
partition (e.g. /dev/hda, not /dev/hda1)? Or the other way around?
I've tried replacing
if [ $PTYPE=="ntfs" ] ; then
if [ $PTYPE==ntfs ] ; then
But still no luck.
So anyone please tell me what I'm doing wrong and how to set this condition checking right.
Thanks for all your help and suggestion.