標籤:function 設定檔 present error write
編寫一個指令碼,全自動安裝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:" name
mkdir -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