【发布时间】:2012-03-14 08:33:47
【问题描述】:
我在脚本中使用 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 文件中。
感谢您对这个权限之谜的帮助。
【问题讨论】:
-
/mnt/WHITE 的 fstab 条目是什么样的?
-
所有者:root,创建和删除;组:根,访问文件;其他:访问文件
标签: bash permissions usb mount