Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 08/06/2008, à 03:01

wHiteweedow

Problème de Script Shell->erreur de syntaxe...

Bonjour, je viens de débuter dans la "programmation" Shell Script... Mais j'ai un problème (Bon début.. neutral) Et j'ai le message qui suit lorsque je tente d'exécuter mon script:

/home/whiteweedow/Bureau/WSInstaller.sh: line 145: erreur de syntaxe : fin de fichier inattendue

J'attends rapidement votre aide pour résoudre ce problème wink.
J'ai hâte de tester mon script tongue!!

Edit: Si vous avez remarqué, c'est un script pour aider à installer un serveur web...

Bon voici le script:

echo "Checking of root rights..."
sudo clear
#=====================
#Custom installation =
#=====================
while [ "$database" = "1" ] || [ "$database" = "2" ] || [ "$database" = "3" ] || [ "$database" = "4" ]; do
echo "== Database =="
echo "1. MySQL (Default)"
echo "2. PostgreSQL"
echo "3. All"
echo "4. None"
read $database
if [ "$database" = "1" ] || [ "$database" = "2" ] || [ "$database" = "3" ] || [ "$database" = "4" ]; then
{
echo "Done !"
}
else
{
    echo "Bad entry! Retry."
}
fi

clear
while [ "$scriptlang" = "1" ] || [ "$scriptlang" = "2" ] || [ "$scriptlang" = "3" ] || [ "$scriptlang" = "4" ]; do
echo "== Misc Script languages =="
echo "1. Perl"
echo "2. Python"
echo "3. All"
echo "4. None (Default)"
read $scriptlang
if [ "$scriptlang" = "1" ] || [ "$scriptlang" = "2" ] || [ "$scriptlang" = "3" ] || [ "$scriptlang" = "4" ]; then
{
    echo "Done !"
}
else
{
    echo "Bad entry! Retry."
}
fi

clear
while [ "$security" = "1" ] || [ "$security" = "2" ]; do
echo "== Security =="
echo "1. Yes (Default)"
echo "2. No"
read $security
if [ "$security" = "1" ] || [ "$security" = "2" ]; then
{
    echo "Done !"
}
else
{
    echo "Bad entry! Retry."
}
fi


#Base installing
echo "Apache2 installing ..."
apache2 apache2-utils apache2-mpm-prefork libapache2-mod-chroot libapache2-mod-auth-pam libapache2-mod-auth-sys-group
echo "PHP5 installing ..."
sudo apt-get install php5-common php5 php5-gd libapache2-mod-php5


#Security installing
if [ "$security" = "1" ]; then
{
    echo "Security installing ..."
    sudo apt-get install libapache2-mod-chroot
}
elif [ "$security" = "2" ]; then
{
    echo "No security will installed"
}
else
{
  echo "System error !"
  echo "Press enter key to exit."
  read exit
}
fi

#Misc script languages installing
if [ "$scriptlang" = "1" ]; then
{
    echo "Perl installing ..."
    sudo apt-get install libapache2-mod-perl2
}
elif [ "$scriptlang" = "2" ]; then
{
    echo "Python installing ..."
    sudo apt-get install libapache2-mod-python
}
elif [ "$scriptlang" = "3" ]; then
{
    echo "Python installing ..."
    sudo apt-get install libapache2-mod-python
    echo "Perl installing ..."
    sudo apt-get install libapache2-mod-perl2
}
elif [ "$scriptlang" = "4" ]; then
{
    echo "Only PHP will installed"
}
else
{
  echo "System error !"
  echo "Press enter key to exit."
  read exit
}
fi

#Database type installing
if [ "$database" = "1" ]; then
{
    echo "MySQL installing ..."
    sudo apt-get install mysql-server libapache2-mod-auth-mysql
}
elif [ "$database" = "2" ]; then
{
    echo "PostgreSQL installing ..."
    sudo apt-get install postgresql libapache2-mod-auth-pgsql
}
elif [ "$database" = "3" ]; then
{
    echo "PostgreSQL installing ..."
    sudo apt-get install postgresql libapache2-mod-auth-pgsql
    echo "MySQL installing ..."
    sudo apt-get install mysql-server libapache2-mod-auth-mysql
}
elif [ "$database" = "4" ]; then
{
    echo "No database will installed"
}
else
{
  echo "System error !"
  echo "Press enter key to exit."
  read exit
}
fi
echo "Webserver are now installed succefully !"
echo "Press enter key to exit."
read exit
exit

Merci d'avance.

Dernière modification par wHiteweedow (Le 08/06/2008, à 03:02)

Hors ligne

#2 Le 08/06/2008, à 08:11

kvb

Re : Problème de Script Shell->erreur de syntaxe...

je n'ai pas regardé ton script en deteil, mais par rapport à l'erreur
je suspecte un problème de syntaxe

dans /home/login par exemple whiteweedow j'ecris sans le h majuscule (comme ton pseudo) ?
Sinon chez moi j'ai 2 pcs sous ubuntu, un se nomme Bureau, l'autre Desktop (à toi de vérifier dans le terminal)
et finalement WSInstaller.sh est à vérifier, est-ce qu'il s'écrit comme ca, est-ce qu'il est situé sur le bureau, les deux points à la fin ne sont pas écrit dans le code ?

edit: est-ce que ce fichier possède les droits d'execution?

Dernière modification par kvb (Le 08/06/2008, à 08:12)

Hors ligne

#3 Le 08/06/2008, à 10:19

Dark-Sham

Re : Problème de Script Shell->erreur de syntaxe...

Moi je pense que c'est le "read exit" à la fin qui pose problème, exit étant une commande. Essaye "read fin" ou tout simplement "read", puisque tu n'utilises pas ce que l'utilisateur entre au clavier. wink

Dernière modification par Dark-Sham (Le 08/06/2008, à 10:20)


Script de sauvegarde/restauration APT

Ubuntu 8.04 "Hardy Heron"
CPU : AMD Athlon XP 2800+ ; GPU : ATI Radeon 9250/9200 Series ; RAM : 2 Gigots + 512 Mégots ; Carte mère : Asus A7N8X-E Deluxe

Hors ligne

#4 Le 08/06/2008, à 10:41

robo58

Re : Problème de Script Shell->erreur de syntaxe...

salut ,

bon apres un regard rapide sur ton code deja je ne vois pas bcp de done
(alors qu'il y a plein de do) :)

sinon je te conseil de revoir tes boucles une a une !!

_ si tu mets un do il faut un done !
_ read dans une boucle il me semble qu'il faut enlever le $ de la variable donc : read database  au lieu de read $database

voila un exemple de boucle pour ton script qui devrait marcher :

while
echo "== Database =="
echo "1. MySQL (Default)"
echo "2. PostgreSQL"
echo "3. All"
echo "4. None"
do
read database
if [ "$database" = "1" ] || [ "$database" = "2" ] || [ "$database" = "3" ] || [ "$database" = "4" ]; then
{
echo "Done !"
break
}
else
{
    echo "Bad entry! Retry."
}
fi
done

#5 Le 08/06/2008, à 10:45

robo58

Re : Problème de Script Shell->erreur de syntaxe...

sinon le lien du guide avance d'ecriture Bash a consommer sans moderation smile

http://abs.traduc.org/abs-5.0-fr/

#6 Le 08/06/2008, à 22:01

wHiteweedow

Re : Problème de Script Shell->erreur de syntaxe...

kvb a écrit :

je n'ai pas regardé ton script en deteil, mais par rapport à l'erreur
je suspecte un problème de syntaxe

dans /home/login par exemple whiteweedow j'ecris sans le h majuscule (comme ton pseudo) ?
Sinon chez moi j'ai 2 pcs sous ubuntu, un se nomme Bureau, l'autre Desktop (à toi de vérifier dans le terminal)
et finalement WSInstaller.sh est à vérifier, est-ce qu'il s'écrit comme ca, est-ce qu'il est situé sur le bureau, les deux points à la fin ne sont pas écrit dans le code ?

edit: est-ce que ce fichier possède les droits d'execution?

J'ai déjà tout vérifié hmm

Hors ligne

#7 Le 08/06/2008, à 22:02

wHiteweedow

Re : Problème de Script Shell->erreur de syntaxe...

Dark-Sham a écrit :

Moi je pense que c'est le "read exit" à la fin qui pose problème, exit étant une commande. Essaye "read fin" ou tout simplement "read", puisque tu n'utilises pas ce que l'utilisateur entre au clavier. wink

J'utilise cette commande dans tout mes scripts pour faire une pause.. (Pour que l'utilisateur puisse lire le résumé)

Hors ligne

#8 Le 08/06/2008, à 22:21

wHiteweedow

Re : Problème de Script Shell->erreur de syntaxe...

robo58 a écrit :

salut ,

bon apres un regard rapide sur ton code deja je ne vois pas bcp de done
(alors qu'il y a plein de do) smile

sinon je te conseil de revoir tes boucles une a une !!

_ si tu mets un do il faut un done !
_ read dans une boucle il me semble qu'il faut enlever le $ de la variable donc : read database  au lieu de read $database

voila un exemple de boucle pour ton script qui devrait marcher :

while
echo "== Database =="
echo "1. MySQL (Default)"
echo "2. PostgreSQL"
echo "3. All"
echo "4. None"
do
read database
if [ "$database" = "1" ] || [ "$database" = "2" ] || [ "$database" = "3" ] || [ "$database" = "4" ]; then
{
echo "Done !"
break
}
else
{
    echo "Bad entry! Retry."
}
fi
done

Aahahh j'avias oublié big_smile
J'ai encore un petit problème: Le menu de sélection ne fonctionne pas mais je crois que je vais être capable de réparer tongue.

Merci !!

Dernière modification par wHiteweedow (Le 08/06/2008, à 22:22)

Hors ligne

#9 Le 08/06/2008, à 23:09

wHiteweedow

Re : Problème de Script Shell->erreur de syntaxe...

Bon, il marche avec le menu de personnalisation en plus tongue.
Je vais travailler sur une version bilingue (Fr/An)

Voici à quoi cela ressemble:

#==================
#Variables define =
#==================
#---Errors
ERR1="One or more errors were detected during the custom installation. (Error 1)"
ERR2="Bad value entered.. The installation. (Error 2)"
ERR3="A value has been changed virtually after the verification of variables. (Error 3)"
#---Startup infos
version="0.8"
website="http://www.xeed.jed.st"
distribution="Ubuntu"
creator="wHiteweedow"
#---Base variables
databaseverif=0
scriptlangverif=0
securityverif=0

echo "Checking of root rights..."
sudo clear
echo $website
echo "**************************"
echo "*       EasyWeb $version      *"
echo "*     Web script tools   *"
echo "*         $distribution         *"
echo "*     By $creator     *"
echo "**************************"
echo "Press enter key to continue."
read continue
clear
#=====================
#Custom installation =
#=====================
echo "== Database =="
echo "1. MySQL (Default)"
echo "2. PostgreSQL"
echo "3. All"
echo "4. None"
read database
if [ "$database" = "1" ] || [ "$database" = "2" ] || [ "$database" = "3" ] || [ "$database" = "4" ]; then
{
echo "Done !"
databaseverif=1
}
else
{
    echo $ERR2
}
fi

clear
echo "== Misc Script languages =="
echo "1. Perl"
echo "2. Python"
echo "3. All"
echo "4. None (Default)"
read scriptlang
if [ "$scriptlang" = "1" ] || [ "$scriptlang" = "2" ] || [ "$scriptlang" = "3" ] || [ "$scriptlang" = "4" ]; then
{
    echo "Done !"
    scriptlangverif=1
}
else
{
    echo $ERR2
}
fi

clear
echo "== Security =="
echo "1. Yes (Default)"
echo "2. No"
read security
if [ "$security" = "1" ] || [ "$security" = "2" ]; then
{
    echo "Done !"
    securityverif=1
}
else
{
    echo $ERR2
}
fi


if [ "$databaseverif" = "1" ] && [ "$scriptlangverif" = "1" ] && [ "$securityverif" = "1" ]; then
{
   echo "All the values are correctly entered !"
   echo "Press enter key to install"
   read install
#Base installing
echo "Apache2 installing ..."
apache2 apache2-utils apache2-mpm-prefork libapache2-mod-chroot libapache2-mod-auth-pam libapache2-mod-auth-sys-group
echo "PHP5 installing ..."
sudo apt-get install php5-common php5 php5-gd libapache2-mod-php5


#Security installing
if [ "$security" = "1" ]; then
{
    echo "Security installing ..."
    sudo apt-get install libapache2-mod-chroot
}
elif [ "$security" = "2" ]; then
{
    echo "No security will installed"
}
else
{
  echo $ERR3
  echo "Press enter key to exit."
  read exit
}
fi

#Misc script languages installing
if [ "$scriptlang" = "1" ]; then
{
    echo "Perl installing ..."
    sudo apt-get install libapache2-mod-perl2
}
elif [ "$scriptlang" = "2" ]; then
{
    echo "Python installing ..."
    sudo apt-get install libapache2-mod-python
}
elif [ "$scriptlang" = "3" ]; then
{
    echo "Python installing ..."
    sudo apt-get install libapache2-mod-python
    echo "Perl installing ..."
    sudo apt-get install libapache2-mod-perl2
}
elif [ "$scriptlang" = "4" ]; then
{
    echo "Only PHP will installed"
}
else
{
  echo $ERR3
  echo "Press enter key to exit."
  read exit
}
fi

#Database type installing
if [ "$database" = "1" ]; then
{
    echo "MySQL installing ..."
    sudo apt-get install mysql-server libapache2-mod-auth-mysql
}
elif [ "$database" = "2" ]; then
{
    echo "PostgreSQL installing ..."
    sudo apt-get install postgresql libapache2-mod-auth-pgsql
}
elif [ "$database" = "3" ]; then
{
    echo "PostgreSQL installing ..."
    sudo apt-get install postgresql libapache2-mod-auth-pgsql
    echo "MySQL installing ..."
    sudo apt-get install mysql-server libapache2-mod-auth-mysql
}
elif [ "$database" = "4" ]; then
{
    echo "No database will installed"
}
else
{
  echo $ERR3
  echo "Press enter key to exit."
  read exit
}
fi
echo "Webserver are now installed succefully !"
echo "Press enter key to exit."
read exit
exit
}
else
{
   echo $ERR1
   echo "Press enter key to exit."
   read exit
   exit
}
fi

Hors ligne