← Back to team overview

sslug-teknik team mailing list archive

Re: BASH: vil ikke sammenkæde strenge

 

Hej Jon.

Problemet ligger i at der er karakterer med skjulte usynlige koder ligende teksten.
Jeg har fixet de meste af dem.


#¡/bin/bash4
echo '1'
USRNME=`whoami`
echo '2'
DOT='.'
echo '3'
MNDOMN='testwebsite.dk'
echo '4'
USRDOMN=${1}
echo '5'
LNK=""
LNK=$(echo ${USRDOMN}${DOT}${USRNME}${DOT}${MNDOMN})
echo '6'
#IP="90${DOT}184${DOT}106${DOT}85"
echo '7'
DIR=${HOME}/PUBLIC_HTML
echo '8'
EMAIL=${2}
echo '9'
echo '$1=' ${1}
echo '10'
echo '$2=' ${2}
echo '11'
echo '$dot=' ${DOT}
echo '12'
echo '$usrnme=' ${USRNME}
echo '13'
echo '$MNDOMN=' ${MNDOMN}
echo '14'
echo '$USRDOMN=' ${USRDOMN}
echo '15'
echo '$LNK=' ${LNK}
echo '16'
echo '$ip= ' ${IP}
echo '17'
echo '$dir=' ${DIR}
echo '18'
if [ ! -d ${DIR} ];
then
    echo '19'
    mkdir ${DIR}
fi
echo '20'
mkdir "${HOME}/PUBLIC_HTML/${LNK}/"
echo '21'
mkdir "/usr/lib/cgi-bin/${LNK}"
echo '22'
echo "<VirtualHost *:80>
 ServerAdmin ${EMAIL}
 ServerName www.${LNK}
 ServerAlias ${LNK}
 DocumentRoot ${DIR}/${LNK}
  # Set Document Root directory options
  <Directory />
    Options FollowSymlnks -Indexes Includes
    # Allow use of .htaccess file
    AllowOverride Limit FileInfo
  </Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/${LNK}
  # Set CGI-BIN directory options
  <Directory /cgi-bin>
    AllowOverride None
    Options +ExecCGI -Multiviews +SymlnksIfOwnerMatch
    Order allow,deny
    Allow from all
  </Directory>
 CustomLog /var/log/apache2/access.log common
 ErrorLog /var/log/apache2/error.log
</VirtualHost>
" > /etc/apache2/sites-available/${LNK}
echo '23'
a2ensite ${LNK}
echo '24'
echo '${IP}        www.${LNK}       ${LNK}' >> /etc/hosts
echo '25'
exec /etc/init.d/apache2 restart
echo '26'
quit


MVh Thomas


Jon Bendtsen wrote:
On 12/03/2011, at 19.27, Jon Bendtsen wrote:

On 12/03/2011, at 19.26, Thomas Rosendal Jensen wrote:

Sådan noget rod!
Kan det laves i et andet sprog?
Er det muligt at realisere i PHP?
Du kan stort set kode hvad som helst i et vilkårligt sprog hvis du virkelig vil. Nogle sprog er dog bedre til nogle ting end andre ting.

Shell scripts er ikke dårligt, du har bare en fejl et eller andet sted, prøv at finde den. Skriv din IF sætning på en anden måde

[kliiiiiiip]



echo '18'
if [ ! -d ${DIR} ] ;
then
  echo '19'
  mkdir ${HOME}/PUBLIC_HTML
fi


output som du har sendt siger at 18 bliver echoet, men 19 osv gør ikke, så må der jo være en fejl lige efter 18.

Du bruger if med et ! foran for at lave en not? eller hvad var din intention?


JonB




bliver den der if regnet korrekt ud? Prøv at skrive den om til en anden måde



JonB

echo '20'
mkdir "${HOME}/PUBLIC_HTML/${LNK}"
echo '21'
mkdir "/usr/lib/cgi-bin/${LNK}"
echo '22'
echo "<VirtualHost *:80>
ServerAdmin ${EMAIL}
ServerName www.${LNK}
ServerAlias ${LNK}
DocumentRoot ${DIR}/${LNK}
# Set Document Root directory options
<Directory />
 Options FollowSymlnks -Indexes Includes
 # Allow use of .htaccess file
 AllowOverride Limit FileInfo
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/${LNK}
# Set CGI-BIN directory options
<Directory /cgi-bin>
 AllowOverride None
 Options +ExecCGI -Multiviews +SymlnksIfOwnerMatch
 Order allow,deny
 Allow from all
</Directory>
CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>
" > /etc/apache2/sites-available/${LNK}
echo '23'
a2ensite ${LNK}
echo '24'
echo '${IP}        www.${LNK}       ${LNK}' >> /etc/hosts
echo '25'
exec /etc/init.d/apache2 restart
echo '26'
quit


Og den giver resultatet:
juac:/home/tj# ./addwebsite test test@xxxxxxx
1
2
3
4
5
: command not found11:
6
7
8
9
$1= test
10
$2= test@xxxxxxx
11
$dot= .
12
$usrnme= root
13
$MNDOMN= testwebsite.dk
14
$USRDOMN= test
15
estwebsite.dk
16
$ip=
17
$dir= /root/PUBLIC_HTML
18
./addwebsite: line 79: syntax error: unexpected end of file
juac:/home/tj#




Hjælp ønskes

Thomas












Follow ups

References