编写一个脚本,全自动安装samba服务,共享的目录。由用户输入,
脚本根据用户的输入自动判断。然后写到samba配置文件,访问samba统一用户为:root密码为:123456,脚本全自动启动服务,请告诉用户samba服务是否运行成功。
!/bin/bash
#write by lijun
#Date 2014-07-16 #==================================================== #the present path #==================================================== PWDDIR=`pwd` #===================================================== #function check error #===================================================== function check_err(){ if [ $? -eq 0 ] then echo "`basename $0` ok!!!">$PWDDIR/ok.log else echo "`basename $0` failed...">$PWDDIR/error.log fi } #====================================================== #1.function check samba install #====================================================== function check_smb_install(){ rpm -q samba if [ $? -eq 0 ] then echo echo "You have already installed samba!" echo else yum install samba -y check_err fi } #==================================================== #selinux and iptables #==================================================== function close(){ /etc/init.d/iptables stop setenforce 0 echo "iptables is stopped!" echo "selinux has set for 0!" } #===================================================== #2.modify the configration in service #===================================================== function modify_conf(){ echo read -p "Would you like to creat a directory?[yes/no]:" a echo if [ $a == "yes" -o $a == "YES" ] then read -p "Please input the directory name only under the '/' like /d_name:" namemkdir -p $name
chmod 777 $name -R
sed -i '101s/share/user/g' /etc/samba/smb.conf
echo " [test `echo $name|awk -F/ '{print $NF}'`] path = $name comment = share `echo $name|awk -F/ '{print $NF}'` valid users = root writeable = yes browseable = yes public = yes">> /etc/samba/smb.conf check_err echo echo "Please set password for root" smbpasswd -a root echo read -p "Restart the service??[yes/no]:" b echo if [ $b == "yes" -o $b == "YES" ] then service smb restart else exit fi echo echo "OK...Congratulations!!!" echo echo "Now you can login the system as user of 'root'" echo "password is '123456'" echo else exit fi } check_smb_install modify_conf close