bash 脚本编程十七 NFS client自动部署

来源:互联网 发布:mac桌面文件不显示桌面 编辑:程序博客网 时间:2024/06/03 15:36

1.自动检测并安装nfs-common,

2.自动创建目录并mount

3.同时检查/etc/fstab文件中是否有配置,没有则加入。确保下次开机能自动mount。

install.sh脚本:

#!/bin/bash source ../../common/tool.shnfsClient="nfs-common"nfsServerFolder=10.112.18.158:/opt/sharenfsClientFolder=~/test_nfs_dirhasDpkg $nfsClientr=$?if [ $r -eq 1 ]then    echo "$nfsClient was installed"else    echo "$nfsClient was not installed"    apt-get install $nfsClientfi#config /opt/share as nfs foldercreateFolder $nfsClientFoldermount -t nfs4 $nfsServerFolder $nfsClientFoldermountString="$nfsServerFolder $nfsClientFolder nfs rsize=8192,wsize=8192,timeo=14,intr"searchString="$nfsServerFolder"mountConfigFile="/etc/fstab"findStringInFile $searchString $mountConfigFilem=$?if [ $m -eq 1 ]then    echo "auto mount was configured"else    echo "auto mount was not configured, configuring..."    echo $mountString >> $mountConfigFilefi

这里用了一个新函数: findStringInFile

这个新函数放在tool.sh脚本中:

#$1 search string#$2 file path#return 1 if found#return 0 if not foundfunction findStringInFile {    h=`grep "$1" $2`    echo "h: $h"    if [ -n "$h" ]    thenreturn 1    elsereturn 0    fi}



原创粉丝点击