存档

文章标签 ‘bash’

自动开设虚拟主机的bash脚本

2010年6月2日

脚本很简单,功能是,自动增加一个以输入域名命名的www根目录,自动生成一个ftp用户,自动创建一个mysql数据库,自动创建一个mysql用户
#!/bin/bash
#输入要增加的域名
echo “Input The Domain”
read
domain=$REPLY
#这里输入ftp密码
echo “Input The Password”
read
ftp_password=$REPLY
#mysql的超级用户名和密码
mysql_root=”root”
mysql_root_pass=”abcdefg”
database_name=${domain//./_}
database_user=${domain//./_}
vhost_file=”${domain}.conf”
echo “Input Mysql Password for Database ${database_name}”
read
database_password=$REPLY
cd /www/wwwroot/
mkdir $domain
chown daemon:daemon $domain
chmod 700 $domain
#生成虚拟机的配置文件
cd /usr/local/apache2/conf/vhost
cp 51rego.com.conf $vhost_file
sed “s/51rego.com/$domain/ig” $vhost_file >temp
cat temp>$vhost_file
#增加ftp虚拟用户和密码
cd /www/users/conf
echo $domain>>vusers.txt
echo $ftp_password>>vusers.txt
db_load -T -t hash -f vusers.txt /etc/vsftpd_login.db
#增加一个ftp账户
cd /etc/vsftpd_user_conf
cp 51rego.com $domain
sed “s/51rego.com/$domain/ig” $domain >temp
cat temp>$domain
#创建mysql数据库
mysql -u${mysql_root} -p${mysql_root_pass} -e “create database ${database_name}”
#创建mysql用户和密码
mysql -u${mysql_root} -p${mysql_root_pass} -e “grant all privileges on [...]