【要求】
实现一键安装并配置samba服务,执行该脚本时需要带一个共享的路径,它是共享的目录,目录若存在,需自动创建samba。要求,任何人都可以访问,并且不需要密码,并且是只读的。
vi /opt/samba.sh
if [ "$# " -ne 1 ]
then echo "运行脚本格式为:$0 /dir/"
exit 1
else if ! echo $1 | grep -q '^/.*' then echo "请提供一个绝对路径!" exit 0fi
fi if ! rpm -q samba > /dev/null
then echo "将要安装samba" sleep 1yum -y install sambaif [ $? -ne 0 ] then echo "samba 安装失败" exit 1fi
fi dirconf= "/etc/samba/smb.conf"
cat >> $dirconf << EOF
[global]workgroup = workgroupsecurity = usermap to guest = bad user
[share]comment= share allpath = $1 browseable = yespublic = yeswritable = no
EOF if [ ! -d $1 ]
then mkdir -p $1
fi chmod 777 $1
chown nobody:nobody $1
echo "www.51xit.top" > $1 /51xit.txtsystemctl start smb
if [ $? -ne 0 ]
then echo "samba服务启动失败,请检查配置文件是否正常"
else echo "samba服务启动正常"
fi
chmod +x /opt/samba.sh
【测试】
/opt/samba.sh /opt/samba/
/opt/samba
目录是绝对路径!
samba-4.8.3-4.el7.x86_64
samba已安装!