Since the error refers to line numbers, it would be easier for use to examine the code if you used "cat -n
script.sh" to add line numbers. It would also allow us to refer to linenumbers in answers.
Also, using indentation would help us understand the logic. The if's/then's/fi's are spread out and are easy to loose track of:
Code:
1 #!/bin/bash
2 # Automatically generate a vhost.conf
3 # to allow access to common in path
4
5
6 VHOSTROOT=/var/www/vhosts/
7
8 # end.
9 clear
10
11
12 if [ -n "$1" ]; then
13 DOMAIN=$1
14 else
15 echo "Enter domain name: "
16 read DOMAIN;
17 fi
18
19
20 if [ ! "`ls -l $VHOSTROOT | grep $DOMAIN`" = "" ]; then
21 echo "> Found ${DOMAIN}"
22 PATHCONF=${VHOSTROOT}${DOMAIN}"/conf"
23 echo "> ${PATHCONF}"
24
25 if [ ! "`ls -l $PATHCONF | grep vhost.conf`" = "" ]; then
26 echo "> vhost.conf for this domain exists."
27 echo "> Overwrite (Y/N)"
28 read yesno
29
30 case "$yesno" in
31 [yY] )
32 cat << "" > ${PATHCONF}/vhost.conf
33 ;;
34 [nN] )
35 echo " "
36 echo "Exiting..."
37 exit 0
38 ;;
39 esac
40 else
41 echo "> no vhost.conf found"
42 fi
43
44
45 (
46 cat <<-EOFM8
47 <Directory /var/www/vhosts/${DOMAIN}/httpdocs/>
48 php_admin_value open_basedir "/var/www/common:/var/www/vhosts/${DOMAIN}/httpdocs:/tmp"
49 </Directory>
50 EOFM8
51 ) > ${PATHCONF}/vhost.conf
52
53
54 echo "> vhost.conf created"
55 echo "> updating Plesk..."
56 /usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=${DOMAIN}
57
58 echo "> done. Restarting Apache..."
59 apachectl -k restart
60 echo "> done."
61 echo " "
62 echo "vhost generation successful"
63 else
64 echo "no"
65 fi
Oddly, when I moved the "; then"'s up, when I added indentation, line 65 actually has a "if" statement. OK, I could have re-edited it so they would look like
Code:
if something
then
statement
statement
fi
which may be better.
Code:
if [ ! "`ls -l $PATHCONF | grep vhost.conf`" = "" ]; then
Maybe using something like
Code:
if [ -f $PATHCONF/vhost.conf ]
would be a cleaner way of checking if vhost.conf exists.
Code:
21 if [ ! "`ls -l $VHOSTROOT | grep $DOMAIN`" = "" ]
...
64 echo " "
65 echo "vhost generation successful"
66 else
67 echo "no"
68 fi
(using your original script so you can see which is line 65)
From the look at it it seems that the if/then/else/fi statements balance out but not the way you want. You have the if inside the case construct and the corresponding else outside of it.
Since ") > ${PATHCONF}/vhost.conf" will overwrite vhost.conf anyway, you don't need
Code:
30 case "$yesno" in
31 [yY] )
32 cat << "" > ${PATHCONF}/vhost.conf
33 ;;
Then you can get rid of
Code:
else
echo "> no vhost.conf found"
So the psuedo code logic could be like
if vhost.conf exists
read yesno
case yesno in [yY])
exit;
esac
create vhost.conf