2016年12月15日 星期四
Bash筆記:Linux 一般帳號 mount cifs
限制
1.只能掛載至登入帳號擁有的目錄下
2.配合 sudo 使用
cifsmount.sh
E_STAT=/usr/bin/stat;
E_MOUNT=/bin/mount;
E_GREP=/bin/grep;
E_WHOAMI=/usr/bin/whoami;
# Check_Mount ='' do'nt check Mounted;
Check_Mount='1';
function help(){ echo Usage: $0 {service} {mount-point} [password];
echo exp:;echo $0 user@//server-name/share-name /home/user;echo $0 user@//server-ip/share-name /home/user password;
};
[ -z $2 ] && { help;exit 1;};
[ -d $2 ] && { Username=${1%@*};Share=${1##*@};}||{ echo "Couldn't chdir to $2: No such directory"; exit 2;};
[ -z "$Share" ] && { help;exit 5;};
[ -z "$Check_Mount" ] || [ -z "$($E_MOUNT|$E_GREP "$Share/ on $2 type cifs")" ]||{ echo "$Share had mounted on $2"; exit 4;};
[ "$SUDO_USER" == "" ] && Real_USER=$($E_WHOAMI)|| Real_USER=$SUDO_USER;
[ "$($E_STAT -c '%U' $2 2>/dev/null)" == "$Real_USER" ]||{ echo "Couldn't chdir to $2: not owner"; exit 3;};
[ -z $3 ] && { :;
_Cmd="$E_MOUNT -t cifs $Share $2 -o uid=$Real_USER,username=$Username";}||{ :;
_Cmd="$E_MOUNT -t cifs $Share $2 -o uid=$Real_USER,username=$Username,password=$3";};
$_Cmd;
cifsumount.sh
E_GREP=/bin/grep;
E_MOUNT=/bin/mount;
E_UMOUNT=/bin/umount;
E_STAT=/usr/bin/stat;
E_WHOAMI=/usr/bin/whoami;
function help(){ echo Usage:$0 {mount-point};echo exp:;echo $0 /home/user;};
[ -z $1 ] && { help;exit 1;};
[ -z "${_T:=$($E_MOUNT | $E_GREP " on $1 type cifs ")}" ] && { echo $1 not mount or not mount on cifs; exit 2;};
[ "$SUDO_USER" == "" ] && Real_USER=$($E_WHOAMI)|| Real_USER=$SUDO_USER;
[ "$($E_STAT -c '%U' $1 2>/dev/null)" == "$Real_USER" ]||{ echo "Couldn't umount $1: not owner"; exit 3;};
_cmd="$E_UMOUNT $1 $2";
$_cmd;
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言