Erreur de syntaxe près du symbole inattendu « fi »
BashLinux
-
jisisv Messages postés 3678 Statut Modérateur -
jisisv Messages postés 3678 Statut Modérateur -
Bonjour,
J'ai l'erreur suivante sur mon bash :
Pouvez vous m'aider ?
Le bash :
#!/bin/sh
#Variable carte Ethernet
DEV=vmbr0
#Pour chaque IP dans le fichier list_ip.txt
#Verification si presence dans le fichier Iptable
# - si present, ne rien faire
# - si absent ajout via iptables -I
while read ip;
do
exist=$(iptables -L | grep $ip);
if [ -z = "$exist" ];
then
#Ajout dans Iptable
iptables -I FORWARD 1 -o $DEV -s $ip -m limit --limit 2000/sec -j ACCEPT
iptables -I FORWARD 2 -o $DEV -s $ip -j DROP
else
#Deja present pas d ajout dans Iptable
fi
done < list_ip.txt
J'ai l'erreur suivante sur mon bash :
Pouvez vous m'aider ?
Le bash :
#!/bin/sh
#Variable carte Ethernet
DEV=vmbr0
#Pour chaque IP dans le fichier list_ip.txt
#Verification si presence dans le fichier Iptable
# - si present, ne rien faire
# - si absent ajout via iptables -I
while read ip;
do
exist=$(iptables -L | grep $ip);
if [ -z = "$exist" ];
then
#Ajout dans Iptable
iptables -I FORWARD 1 -o $DEV -s $ip -m limit --limit 2000/sec -j ACCEPT
iptables -I FORWARD 2 -o $DEV -s $ip -j DROP
else
#Deja present pas d ajout dans Iptable
fi
done < list_ip.txt
A voir également:
- Bash: erreur de syntaxe près du symbole inattendu « newline »
- Symbole numero ✓ - Forum Word
- Symbole poisson témoin de jéhovah - Accueil - Maison
- Symbole attention word ✓ - Forum Word
- Numero symbole ✓ - Forum Bureautique
- Instagram connexion impossible erreur inattendue ✓ - Forum Instagram
3 réponses
Remarque ton nom de variable exists n'est pas très heureux (ressemble au mot-clé exit. Utilide plutôt des noms en UPPERCASE_WITH_UNDERSCORES
Ceci dit,
Pour ton test, ton utilisation est erronée , examine ceci:
johand@bata:~$ unset truc
johand@bata:~$ if [ -z $truc ] ; then echo BAD; fi
BAD
johand@bata:~$ if [ -z = "$truc" ] ; then echo BAD; fi
johand@bata:~$ truc=123
johand@bata:~$ if [ -z $truc ] ; then echo BAD; fi ; echo OK
OK
[ -z = $BLAH ] retourne toujours faux !
En outre, et c'est le plus important, le corps du else est vide ce qui fournit une erreur. Supprime cette branche ou mets-y une instruction valide.
exemple:
Gates gave ^W sold you the windows.
GNU gave us the whole house.(Alexandrin)
Ceci dit,
Pour ton test, ton utilisation est erronée , examine ceci:
johand@bata:~$ unset truc
johand@bata:~$ if [ -z $truc ] ; then echo BAD; fi
BAD
johand@bata:~$ if [ -z = "$truc" ] ; then echo BAD; fi
johand@bata:~$ truc=123
johand@bata:~$ if [ -z $truc ] ; then echo BAD; fi ; echo OK
OK
[ -z = $BLAH ] retourne toujours faux !
En outre, et c'est le plus important, le corps du else est vide ce qui fournit une erreur. Supprime cette branche ou mets-y une instruction valide.
exemple:
#!/bin/sh if [ -z $1 ] ; then echo "No param" else # TTT echo "Param1 is $1" fi
Gates gave ^W sold you the windows.
GNU gave us the whole house.(Alexandrin)