我在脚本中使用mount命令在Bash中安装usb驱动器。我关闭了haldameon,并且autofs以便驱动器不会自动挂载。
一切都在Root中工作,如果你在root中运行它,那么切换到非root帐户。但是,当从关闭进入非root帐户然后运行脚本时,驱动器将挂载但不允许写入命令。
这是一些伪代码:
关闭autofs,haldaemon 将驱动器手动插入计算机 运行山 尝试使用目录/ mnt /
编写错误权限
这是关闭自动挂载代码。
#stop automounter
/etc/init.d/autofs stop
#stop hal daemon, this is the hardware abstraction layer
/etc/init.d/haldaemon stop
这是挂载代码:
#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
以下是包含错误的复制代码:
echo "Copying Test Files to Drives"
#copy
cp $copyfile "/mnt/WHITE"
cp $copyfile "/mnt/GREEN"
cp $copyfile "/mnt/RED"
sync
sleep 2
mount,/ etc / init.d / autofs stop,/ etc / init.d / haldaemon stop的命令也在sudoers文件中。
感谢您对此权限的帮助。
答案 0 :(得分:1)
检查mnt驱动程序的权限
ls -l
他们可能是root所有,因此你不能写信给他们。
可能需要选择它们:
chown domain:user /mnt/{WHITE|GREEN|RED}
答案 1 :(得分:1)
可能是你没有在mount / fstab中传递一些参数。您可以尝试在脚本中显式传递选项,如此;
mount -L WHITE /mnt/WHITE -o rw
具体为其提供读/写权限,或
mount -L WHITE /mnt/WHITE -o rw,uid=test,gid=test
使用读/写进行安装以及使用户可以访问设备:group test