achuthpnr
August 23rd, 2013, 08:28 AM
I am trying to write a script to mount an ntfs partition or unmount it if already mounted (for learning purposes). As a default I open the mounted partition in thunar.
#! /bin/bash
# mount or unmount a ntfs partition using ntfs-3g
tobemounted=/dev/sda2 #this partition must exist
mountfolder=/mnt/Data/ #this folder must exist
ismounted=$(cat /etc/mtab | grep -c $tobemounted)
echo $ismounted
if [ $ismounted = 1 ] ; then
title="Partition already mounted"
question="unmount"
else
title="Partition not mounted"
question="mount"
fi
if zenity --question --timeout 20 --title="$title" --text="Do you want to $question \n $tobemounted ?" --height=100 --width=300; then
if [ $ismounted = 1 ] ; then
echo 'unmount'
sudo umount $mountfolder
else
echo 'mount'
sudo ntfs-3g $tobemounted $mountfolder
thunar $mountfolder #opens dir in thunar
fi
else
thunar $mountfolder #opens dir in thunar
echo 'default no'
fi
ismounted=$(cat /etc/mtab | grep -c $tobemounted)
echo $ismounted
exit
i see the dialog box appear, but in all cases I get the default no operation. Where am I going wrong?
Thanks.
#! /bin/bash
# mount or unmount a ntfs partition using ntfs-3g
tobemounted=/dev/sda2 #this partition must exist
mountfolder=/mnt/Data/ #this folder must exist
ismounted=$(cat /etc/mtab | grep -c $tobemounted)
echo $ismounted
if [ $ismounted = 1 ] ; then
title="Partition already mounted"
question="unmount"
else
title="Partition not mounted"
question="mount"
fi
if zenity --question --timeout 20 --title="$title" --text="Do you want to $question \n $tobemounted ?" --height=100 --width=300; then
if [ $ismounted = 1 ] ; then
echo 'unmount'
sudo umount $mountfolder
else
echo 'mount'
sudo ntfs-3g $tobemounted $mountfolder
thunar $mountfolder #opens dir in thunar
fi
else
thunar $mountfolder #opens dir in thunar
echo 'default no'
fi
ismounted=$(cat /etc/mtab | grep -c $tobemounted)
echo $ismounted
exit
i see the dialog box appear, but in all cases I get the default no operation. Where am I going wrong?
Thanks.