Tôi có một tập lệnh thêm người dùng mới và tạo một máy chủ ảo cho tên miền người dùng. Kịch bản hoạt động tuyệt vời với một ngoại lệ ... trong / etc / apache2 / sites-Available / tất cả các tệp máy chủ ảo của tôi có hai bản sao, một có e và một không có.
Tôi tin rằng vấn đề của tôi nằm ở khi tôi sử dụng lệnh SED. Tôi có thể có ý kiến thứ hai không?
Đây là kịch bản:
# 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
Xin lỗi, sau khi gõ mà tôi nhận ra lỗi của mình, khi sử dụng lệnh SED, tôi có tùy chọn -i để chỉnh sửa tệp "nội tuyến" mà không tạo bản sao. Vì một số lý do, tôi đã thêm lệnh e, được cho là thêm tập lệnh. Tôi đã thay đổi -ie thành -i và kịch bản hoạt động khi cần thiết. Tôi không thể trả lời câu hỏi của riêng tôi vì vậy tôi đã thêm một nhận xét.
—
jason.dot.h