Skip to content

Instantly share code, notes, and snippets.

@tperalta82
Created June 23, 2016 16:38
Show Gist options
  • Save tperalta82/2951a1d98161afabd41d591a240e8535 to your computer and use it in GitHub Desktop.
Save tperalta82/2951a1d98161afabd41d591a240e8535 to your computer and use it in GitHub Desktop.
Nginx Split vhosts
#!/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