Install the samba service using shell

Source: Internet
Author: User

Write a script to fully install the samba service and share the directory. Input by the user,
The script is automatically determined based on user input. Then write to the samba configuration file and access Samba. The unified user is root.

The password is 123456. The script automatically starts the service. Please tell the user whether the samba service runs successfully.

! /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 "wocould you like to creat a directory? [Yes/No]:"
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 '000000 '"
Echo
Else
Exit
Fi
}
Check_smb_install
Modify_conf
Close


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.