Reputation: 517
I am using the mount command in a script to mount a usb drive in Bash. I have turned off haldameon, and autofs so that the drive will not automount.
Everything works in Root and also if you run it in root then switch to the non-root account. However when coming from shutdown into the non-root account and then running the script the drive will mount but not allow write commands.
Here is some pseudo code:
turn off autofs, haldaemon insert drives manually into the computer run the mount try to write using the directory /mnt/
error permissions
Here is the turn off automount code.
#stop automounter
/etc/init.d/autofs stop
#stop hal daemon, this is the hardware abstraction layer
/etc/init.d/haldaemon stop
Here is the mount code:
#WHITE---------------------------------------
if grep -qs '/mnt/WHITE' /proc/mounts; then
echo "WHITE Mounted re-mounting Unnecessary"
else
#check if the directories are already there and remove if necessary
if [ -d "/mnt/WHITE" ] ; then
rmdir "/mnt/WHITE"
fi
#create directory and mount by label
mkdir -p /mnt/WHITE
mount -L WHITE /mnt/WHITE
#check if the WHITE USB Drive is mounted to the correct directory
if [ -d "/mnt/WHITE" ] ; then
#check if USB is mounted by location
if grep -qs '/mnt/WHITE' /proc/mounts; then
echo "WHITE Mounted"
else
echo $errorstatus_white_mount
exit 1
fi
else
echo $errorstatus_white_mount
exit 1
fi
fi
Here is the copy code that has the error:
echo "Copying Test Files to Drives"
#copy
cp $copyfile "/mnt/WHITE"
cp $copyfile "/mnt/GREEN"
cp $copyfile "/mnt/RED"
sync
sleep 2
Also the commands for mount, /etc/init.d/autofs stop, /etc/init.d/haldaemon stop are in the sudoers file.
Thanks for the help with this permission mystery.
Upvotes: 1
Views: 3051
Reputation: 572
It might be that you're not passing some parameters in the mount/fstab. You could try explicitly passing options in your script like so;
mount -L WHITE /mnt/WHITE -o rw
which specifically gives it read/write permissions, or
mount -L WHITE /mnt/WHITE -o rw,uid=test,gid=test
which mounts with read/writes as well as making the device accessible for user:group test
Upvotes: 2
Reputation: 1767
Check the permissions on the mnt drivers
ls -l
they are probably owned by root hence why you cant write to them.
Might need to chown them:
chown domain:user /mnt/{WHITE|GREEN|RED}
Upvotes: 2