Created
June 23, 2016 16:38
-
-
Save tperalta82/2951a1d98161afabd41d591a240e8535 to your computer and use it in GitHub Desktop.
Nginx Split vhosts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ ! -d "ngxvhosts" ]; then | |
mkdir ngxvhosts | |
fi | |
if [ -f "xx*" ]; then | |
rm xx* | |
fi | |
echo $1 $2 $3 | |
csplit nginx.conf '/\s*\<server\>\s*/' {*} | |
#new_name ='' | |
for i in xx* | |
do | |
if grep -oP '(?<=server_name).+;' $i | |
then | |
result=`grep -oP '(?<=server_name).+;' $i` | |
new_name=`echo $result|awk '{print $1}'` | |
new_name=${new_name%';'}.conf | |
mv $i ngxvhosts/$new_name | |
else | |
rm $i | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment