shell安裝samba服務

來源:互聯網
上載者:User

標籤: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


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.