Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1476725
  • 博文数量: 463
  • 博客积分: 10540
  • 博客等级: 上将
  • 技术积分: 5450
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-12 08:30
文章分类

全部博文(463)

文章存档

2014年(2)

2012年(14)

2011年(42)

2010年(18)

2009年(78)

2008年(35)

2007年(182)

2006年(92)

我的朋友

分类: LINUX

2009-05-21 19:44:14

#! /bin/sh
ROOT_UID=0
E_NOTROOT=67

#判断是否root用户
if [ "$UID" -ne "$ROOT_UID" ]
then
    echo "Must be root to run this script."
    exit $E_NOTROOT
fi

#输入用户名
echo -n "Enter User Name:"
    read UserName
if [ ! -n "$UserName" ]; then
    echo "User Name is empty"
    exit 0
fi

#判断用户是否存在.存在就退出
for UN in `cat /etc/passwd |grep -i $UserName |awk -F ":" '{print $1}'`
do
if [[ $UserName == $UN ]]; then
                echo "Sorry,User $UserName is exists"
                exit 0
        else
                echo aaaaaa
        fi
done

#用户空间密码
stty -echo    # 关闭屏幕的echo.
echo -n "Enter password:"
    read pw1
echo
echo -n "Retype Enter password:"
    read pw2
if [ "$pw1" == "$pw2" ] ; then
    Pawd=$pw1
else
    echo "Sorry, passwords do not match."
    exit 0
fi
stty echo     # 恢复屏幕的echo.
echo
echo -n "Enter Domain Name:"
    read DomainName
if [ ! -n "$DomainName" ]; then
    echo "User DomainName is empty"
    exit 0
fi

#MySql管理员密码
stty -echo    # 关闭屏幕的echo.
echo -n "Enter LocalHost Mysql Root Password:"
    read Mysqlpwd
if [ ! -n "$Mysqlpwd" ]; then
    echo " Mysql Password is empty"
    exit 0
fi
stty echo     # 恢复屏幕的echo.

#检查MySql连接是否正常,shell中的if语法,-z参数判断条件是否为0
/usr/bin/mysqladmin -uroot -p$Mysqlpwd ping &>/dev/null
if [ -z $? ]; then
                echo "MySql connection is fail"
        else
                #mysql用户加入
                mysql -uroot -p"$Mysqlpwd" -e "create database $UserName;"
                mysql -uroot -p"$Mysqlpwd" -e "use $UserName;GRANT SELECT, INSERT, UPDATE, DELETE, INDEX, ALTER, CREATE, LOCK TABLES, CREATE TEMPORARY TABLES, DROP, REFERENCES ON ${UserName}.* TO ${UserName}@localhost IDENTIFIED BY '$Pawd';"
                mysql -uroot -p"$Mysqlpwd" -e "flush privileges;"
                echo "Create  databases $UserName finish."
fi

DomainNamePrefix=$UserName

#useradd加入
useradd $UserName -s /sbin/nologin -d /home/$UserName
mkdir /home/$UserName/public_html
chmod 755 /home/$UserName
chown ${UserName}:${UserName}  /home/$UserName/public_html
usermod  -d /home/$UserName/public_html/ $UserName
echo ${UserName}:$Pawd | chpasswd
gpasswd -a apache $UserName
echo "Create User $UserName finish."

Userid=$(id -u $UserName)
Groupsid=$(id -g $UserName)

echo "Get uid and gid id finish"

Date=$(date -d "today" +"%y%m%d%H%M")
cp  /etc/httpd/conf/httpd.conf  /etc/httpd/conf/httpd.conf.${Date}.bak
echo -ne "
# This Info add time is `date`.

    SuexecUserGroup \"#${Userid}\" \"#${Groupsid}\"
    ServerName $DomainName
    DocumentRoot /home/$UserName/public_html
    ErrorLog logs/${UserName}_error.log
    CustomLog \"|/usr/sbin/cronolog /var/log/httpd/${UserName}_access_%Y%m%d.log\"   combined
    DirectoryIndex index.html index.htm index.php

   
        Options Indexes IncludesNOEXEC
        allow from all
        AllowOverride None
   

" >  /etc/httpd/conf.d/$UserName.conf

service httpd reload
echo "Create Apache user is  finish"
#quota的加入
#edquota -p user $UserName
sed -e "s/model/$UserName/g" /etc/awstats/awstats.model.conf >/etc/awstats/awstats.$UserName.conf
echo "$UserName" >> /etc/vsftpd/chroot_list
echo "Create Quota and awstats is finish"

阅读(943) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~