因此,我试图为我的Ubuntu LAMP服务器制作一个.sh脚本,以使其更容易将新网站添加到apache2中,但是当我尝试执行时,出现错误
: bad variable name read: website
我已经进行了一些搜索,但找不到所需的答案,并且在脚本中有很多地方出现了与导致错误的行匹配相同设置的行。这是我认为引起错误的生产线上的设置
read -p 'What is the website title (no spaces): ' website
这是整个脚本:
echo Starting website builder
read -p 'What is the website title (no spaces): ' website
echo Website title saved as $website
echo creating storage folder
mkdir -p /var/www/$website
echo changing file permissions
chown -R $name:$name /var/www/$website
chmod -R 755 /var/www/$website
echo creating test file
echo <html> >> /var/www/$website/index.html
echo <head> >> /var/www/$website/index.html
echo <title>Success</title> >> /var/www/$website/index.html
echo </head> >> /var/www/$website/index.html
echo <body> >> /var/www/$website/index.html
echo <h1>$website is operational</h1> >> var/www/$website/index.html
echo </body> >> /var/www/$website/index.html
echo </html> >> /var/www/$website/index.html
clear
cat /var/www/$website/index.html
echo
read -p "press [Enter] to continue"
clear
echo creating $website.conf file
echo <VirtualHost *:80> >> /etc/apache2/sites-available/$website.conf
read -p 'Enter ServerName: ' ServerName
echo ServerName $ServerName >> /etc/apache2/sites-available/$website.conf
read -p 'Enter ServerAlias (domain name): ' ServerAlias
echo ServerAlias $ServerAlias >> /etc/apache2/sites-available/$website.conf
read -p 'Enter ServerAdmin: ' ServerAdmin
echo ServerAdmin $ServerAdmin >> /etc/apache2/sites-available/$website.conf
echo DocumentRoot var/www/$website >> /etc/apache2/sites-available/$website.conf
echo ErrorLog ${APACHE_LOG_DIR}/error.log >> /etc/apache2/sites-available/$website.conf
echo CustomLog ${APACHE_LOG_DIR}/access.log combined >> /etc/apache2/sites-available/$website.conf
echo </VirtualHost>
clear
cat /etc/apache2/sites-available/$website.conf
echo
read -p "press [Enter] to continue"
clear
echo activating website
a2ensite $website
service apache2 restart
echo Open a web browser on any pc and visit $ServerAlias. If you have errors make sure the alias and external ip was properly set up on the domainservice you signed up with.
read -p 'Process completed. Press [Enter] to end.'
clear
混乱的错误消息指出Windows行尾存在问题。您可以使用以下命令将文件中的行尾转换为换行符(Unix格式):
sed -i 's/\r$//' /path/to/your/script
或(您可能需要先安装dos2unix
):
dos2unix /path/to/your/script
进一步阅读:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句