一键安装samba服务
写个shell脚本,能够实现一键安装并配置samba服务,执行该脚本时需要带一个参数,为共享的目录,目录若不存在,需自动创建。
要求,任何人都可以访问,且不用密码,并且目录是只读的。
#!/bin/bash
#这个脚本用来一键安装并配置samba
#作者:www.cnbugs.com
#日期:2018-12-17
if [ "$#" -ne 1 ]
then
echo "运行脚本的格式为:$0 /dir/"
exit 1
else
if ! echo $1 |grep -q '^/.*'
then
echo "请提供一个绝对路径。"
exit 1
fi
fi
if ! rpm -q samba >/dev/null
then
echo "将要安装samba"
sleep 1
yum install -y samba
if [ $? -ne 0 ]
then
echo "samba安装失败"
exit 1
fi
fi
cnfdir="/etc/samba/smb.conf"
cat >> $cnfdir <<EOF
[share]
comment = share all
path = $1
browseable = yes
public = yes
writable = no
EOF
if [ ! -d $1 ]
then
mkdir -p $1
fi
chmod 777 $1
echo "test" > $1/test.txt
#假设系统为CentOS7
systemctl start smb
if [ $? -ne 0 ]
then
echo "samba服务启动失败,请检查配置文件是否正确。"
else
echo "samba配置完毕,请验证。"
fi
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。