我有一个添加新用户并为用户域名创建虚拟主机的脚本。该脚本可以很好地运行,但有一个例外...在/ etc / apache2 / sites-available /中,我所有的虚拟主机文件都有两个副本,一个带有e,一个没有。
我相信我的问题出在使用SED命令时。我可以再发表意见吗?
这是脚本:
# set the working directory
dir=$(pwd)
# request the new domain name
printf "Enter the new domain name, without the www (i.e newdomain.com):\n"
read newdomain
# request the new username
printf "Enter the new username (i.e newusername):\n"
read username
# create the new user
sudo adduser $username
# copy the virtual host to sites-available
sudo cp /templates/domain-vhost /etc/apache2/sites-available/$newdomain
# echo results
echo "Successfully created the virtual host file at: /etc/apache2/sites-available/$newdomain.."
# change the domain name in the virtual host file
sudo sed -ie "s/NEWDOMAINNAME/$newdomain/" /etc/apache2/sites-available/$newdomain
# echo results
echo "Modified the virtual host to reflect the new domain: $newdomain.."
# change the directory path in the virtual host
sudo sed -ie "s/NEWUSERNAME/$username/" /etc/apache2/sites-available/$newdomain
# echo results
echo "Successfully modified the new virtual host file.."
# enable the site with apache
cd /etc/apache2/sites-available/
sudo a2ensite $newdomain
# echo results
echo "Successfully enabled the $newdomain.."
# change to previous working directory
cd $dir
# reload apache
sudo /etc/init.d/apache2 reload
# notify user of action
echo "Finished creating the new domain, $newdomain, and restarted Apache.."
3
抱歉,键入后我意识到自己的错误,在使用SED命令时,我使用了-i选项来编辑文件“内联”而不创建副本。由于某种原因,我还添加了e命令,该命令应该添加脚本。我将-ie更改为-i,并且脚本可以根据需要运行。我还不能回答自己的问题,因此添加了评论。
—
jason.dot.h 2011年