Linux Bash - erreur de syntaxe fin de fichier prématurée

Résolu/Fermé
bayano - 6 mars 2017 à 05:12
 bayano - 8 mars 2017 à 18:03
Bonjour,

j'ai un problème au niveau d'un mini script bash pour envoyer une notifications

j'aimerais savoir pourquoi?

./notifications.sh: ligne 7: erreur de syntaxe : fin de fichier prématurée

#!/bin/bash
cat collaborators.txt|while read collabs
do
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "$collabs" http://monserveur/NotifCollaborators
done
exit



A voir également:

1 réponse

UnGnU Messages postés 1158 Date d'inscription lundi 2 mai 2016 Statut Contributeur Dernière intervention 22 décembre 2020 157
6 mars 2017 à 08:51
Salut,

Peux-tu afficher ton script avec l'option -A de la commande cat :
cat -A ton_script


Sinon, il est préférable d'utiliser la syntaxe de redirection plutôt qu'un pipe :

#!/bin/bash
while read collabs
do
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "$collabs" http://monserveur/NotifCollaborators
done < collaborators.txt
exit

0
> Peux-tu afficher ton script avec l'option -A de la commande cat

$ cat -A notif.sh
#!/bin/bash^M$
cat collaborators.txt|while read collabs^M$
do^M$
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "$collabs" http://monserveur/NotifCollaborators^M$
done^M$
exit^M$


> il est préférable d'utiliser la syntaxe de redirection

Maintenant j'ai cette erreur

./notif.sh: ligne 5: erreur de syntaxe près du symbole inattendu « done »
'/notif.sh: ligne 5: `done < collaborators.txt


Synopsis:

Pour envoyer une notification au collaborateur 1
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "&email=collaborator1%40monserveur.tld" http://monserveur/NotifCollaborators


J'ai 15 collaborateurs (15 emails)

avec mon script je veux importer les 15 emails et envoyer 15 notifications.

Alternative:

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "&email=collaborator1%40monserveur.tld" http://monserveur/NotifCollaborators
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "&email=collaborator2%40monserveur.tld" http://monserveur/NotifCollaborators
...
..
.
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "&email=collaborator15%40monserveur.tld" http://monserveur/NotifCollaborators


Merci pour votre aide.
0
UnGnU Messages postés 1158 Date d'inscription lundi 2 mai 2016 Statut Contributeur Dernière intervention 22 décembre 2020 157 > bayano
6 mars 2017 à 13:36
#!/bin/bash^M$
;-\
Ne cherche pas plus loin le responsable c'est toi et surtout le fait d'avoir écrit ton script sous un système Micro$oft ;-((

Soit tu retapes ton script sous Gnu/Linux, soit tu passes un petit coup de dos2unix
0
bayano > UnGnU Messages postés 1158 Date d'inscription lundi 2 mai 2016 Statut Contributeur Dernière intervention 22 décembre 2020
Modifié par bayano le 8/03/2017 à 18:04
Je ss sous Manjaro Linux (manjaro.org) c'est juste que j'ai ajouter un retour à la ligne a mon script bash... Je ne savais pas que cela pose problème o_O

C'est résolu !! Merci... merci pour votre assistance :)


Très cordialement,
0