小例子: 挂载可移动媒介
#/bin/bash
[ $# == 0 ] && echo "Usage: $0 {H,F}" && exit 7
# 1.create mount directory
# 2.mount the given flash disk, hard disk, U disk and so on. Belong to Storage Media.
#mount HarDisk or flashDisk
WHERE_TO_MOUNT=${HOME}//NTFS_HARD_DISK/
WHERE_TO_MOUNT18I=${HOME}/NTFS_HARD_DISK18I/
#Auto Find the location of Media.
LOC=`sudo fdisk -l | tail -n 1 | cut -d " " -f 1`
echo $LOC
# mkdir ${WHERE_TO_MOUNT}
#use ‘sudo fdisk -l‘ find the location of the Storage Media. Then we can mount it.
#H: HarDisk
#F: flashDisk
if [ $1 == "H" ]; then
#sudo mount -t ntfs /dev/sdb2 ${WHERE_TO_MOUNT} -o gid=${USER},uid=${USER},umask=022
sudo mount -t ntfs $LOC ${WHERE_TO_MOUNT} -o gid=${USER},uid=${USER},umask=022
elif [ $1 == "F" ]; then
#sudo mount /dev/sdb1 ${WHERE_TO_MOUNT} -o gid=${USER},uid=${USER},umask=022
sudo mount $LOC ${WHERE_TO_MOUNT} -o iocharset=utf8,gid=${USER},uid=${USER},umask=022
elif [ $1 == "G" ]; then
#sudo mount /dev/sdb1 ${WHERE_TO_MOUNT} -o gid=${USER},uid=${USER},umask=022
#sudo mount /dev/sdb1 ${WHERE_TO_MOUNT18I} -o iocharset=utf8,gid=${USER},uid=${USER},umask=022
sudo mount /dev/sdc1 ${WHERE_TO_MOUNT18I} -o iocharset=utf8,gid=${USER},uid=${USER},umask=022
#sudo mount /dev/sdb1 ${WHERE_TO_MOUNT} -o iocharset=utf8,gid=${USER},uid=${USER},umask=022
else
echo "What are you going to do..?"
fi
# Noter: 20130321 by N
# write ‘sudo‘ in text, when execute, just do ‘./xx.sh‘
# no ‘sudo‘ inside, when execute, do ‘sudo ./xx.sh‘
#The Format of this Scritps: [07072013]
# -> sudo inside scripts, do ‘./mntXXX {H,F}‘
# -> sudo not inside scripts, do ‘sudo ./mntXXX {H,F}‘
本文出自 “andyhdchoice” 博客,请务必保留此出处http://andyhdchoice.blog.51cto.com/1521623/1548803
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。