• Shell脚本一键安装Samba服务


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

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


    #!/bin/bash

    if [ "$#" -ne 1 ]     ###判断参数个数是否唯一,不是则进行then的逻辑处理
    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

    #测试#
    /opt/samba.sh /opt/samba/

    道阻且长,行则将至!加油! --不是冷漠
  • 相关阅读:
    京东精益敏捷教练分享:敏捷助力产品创新!
    设计规范 | 详解组件控件结构体系
    Axure响应式进阶
    通讯录表设计
    TEST1
    c#练习四单元总结
    窗体控件应用总结(1)
    .NET(c#理解)
    test2-11
    test1-1
  • 原文地址:https://www.cnblogs.com/bushilengmo/p/13584914.html
Copyright © 2020-2023  润新知