一键安装部署samba服务

创建一个samba服务

shell要求

写一个shell脚本,能够实现一键安装并配置samba服务,执行该脚本时需要带一个共享的路径,
它是共享的目录,目录若存在,需自动创建samba。

要求,任何人都可以访问,并且不需要密码,并且是只读的。

shell分析

1、需要判断的用户给出的是目录是不是绝对路径,即是否以‘/’开头
2、脚本需要判断samba服务是否已经安装,若已经安装了就不需要执行yum -y install samba 了
3、配置文件可以使用sed -i
4、samba配置可以参考http://www/apelearn.com/study_v2/chapter24.html#id1
其中在centos7上的新samba配置稍微有点差异,本题要求的任何人都可以访问,不需要修改
security这一项目,保持默认即可。

shell配置命令

vim /opt/samba.sh    #创建新的sh文件


#!/bin/bash
if [ "$#" -ne 1 ]
then
   echo "运行脚本格式为:$0 /dir/"
exit 1
else
   if ! echo $1 |grep -q '^/.*'
   then
        echo "请提供一个绝对路径。"
        exit 0
   fi
fi

if ! rpm -q samba >/dev/null
then
   echo "将要安装samba"
   sleep 1
   yum -y install samba
   if [ $? -ne 0 ]
   then
      echo "samba 安装失败"
      exit 1
   fi
fi

dirconf="/etc/samba/smb.conf"
cat >> $dirconf << EOF
[global]
        workgroup = workgroup
        security = user
        map to guest = bad user
[share]
        comment= share all
        path = $1
        browseable = yes
        public = yes
        writable = no
EOF

if [ ! -d $1 ]
then
   mkdir -p $1
fi

chmod 777 $1
chown nobody:nobody $1
echo "www.51xit.top" > $1/51xit.txt

systemctl start smb
if [ $? -ne 0 ]
then
   echo "samba服务启动失败,请检查配置文件是否正常"
else
   echo "samba服务启动正常"
fi


chmod +x /opt/samba.sh   #添加可执行权限
  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值