日常笔记

Linux配置nfs共享脚本

2017-05-13  本文已影响97人  Lisong
#!/bin/bash
rpm -q nfs-utils
if [[ $? -eq 0 ]];then
    echo "nfs安装成功"
else
    yum install -y nfs-utils
    if [[ $? -eq 0 ]];then
        echo "安装成功"
    else
        echo "安装失败"
    fi
fi

read -p "是否保留之前的共享:[y/n] " -t 20 ap
if [[ ${ap} = "n" ]]; then
    echo "保留之前的共享配置"
    while true; do
    read -p "共享目录:" -t 20 gdir
    read -p "允许访问的IP:" -t 20 xip
    read -p "读写权限:[ro/rw] " -t 20 qx
    cat <<- EOF > /etc/exports
    ${gdir}  ${xip}(${qx,sync})
    EOF
    cat /etc/exports
    read -p "是否继续共享:[y/n] "  op
    if [ ${ap} == "n" ]; then
        break;
    fi
    done

else
    echo "删除之前的共享配置"
    while true; do
    read -p "共享目录:" -t 20 gdir
    read -p "允许访问的IP:" -t 20 xip
    read -p "读写权限:[ro/rw] " -t 20 qx
    cat <<- EOF >> /etc/exports
    ${gdir}  ${xip}(${qx,sync})
    EOF
    cat /etc/exports
    read -p "是否继续共享:[y/n] "  op
    if [ ${op} == "n"]; then
        break;
    fi
    done
fi

service nfs restart
showmount -e 127.0.0.1
echo "脚本执行完毕!"

上一篇下一篇

猜你喜欢

热点阅读