Aller au contenu

Shell unix: comment afficher le contenu d'un fichier txt dans le corps d'un mail?


jakol

Messages recommandés

Posté(e)

Bonjour,

Je souhaiterais savoir comment afficher le contenu d'un fichier .txt dans le corps d'un mail envoyé à partir d'un serveur unix.

J'ai fait les commandes suivantes. Je peux envoyer le mail avec le fichier en pj.

./init/appli status >statutappli.txt && cat statutappli.txt | mail -s "Statutappli" jakol@unix.fr

Merci pour votre retour

jakol

 

Posté(e)

Merci pour ton retour

j'ai lancé la commande suivante. Il y a pièce mais pas le contenu du fichier dans le corps du mail. Il y a un truc que je n'ai pas compris...

mail -s "Statutappli" jakol@unix.fr < statutaplpi.txt 

 

Si tu as une idée...? Merci

 

Posté(e)

J'ai modifié ton dernier poste pour masquer l'adresse 😉

 

Peux-tu tester comme ceci (le -t manquait dans ton dernier post) :

mail -s "Statutappli" -t jakol@unix.fr < statutaplpi.txt

 

Posté(e)
Il y a 5 heures, jakol a écrit :

mail -s "Statutappli" jakol@unix.fr < statutaplpi.txt 

Si tu as une idée...? Merci

Là il semble y avoir une coquille dans le nom du fichier. Vérifier le nom du fichier. qu’il soit accessible et qu’il ne soit pas vide.

Tester en ligne de commande en mode verbeux:

mail -v -s "StatutAppli" toto@pluton.com < fichier.txt

Deuxième problème: quel client mail utilises-tu pour vérifier le résultat?

Posté(e)

 le fichier n'est pas vide. Il est accessible ( 777).

mail -v -s "StatutAppli"  toto@pluto.com < statutappli.txt
Mail Delivery Status Report will be mailed to <nomdelappli>.

pour le client: thunderbird en IMAP

 

 

Posté(e)
Il y a 16 minutes, jakol a écrit :

pour le client: thunderbird en IMAP

Pour résumer, tu reçois un mail, mais apparemment vide.

Tu as checké la source du mail sous thunderbird?

C'est quoi comme unix?

Le fichier ne contient pas de caractère particulier?

As-tu essayé la commande 

echo 'test mail' | mail -v -s 'statut' toto@pluton.com

Citer

 

Posté(e)

J'ai des caractères illisibles pour la commande

mail -v -s "StatutAppli" toto@pluton.com < fichier.txt

 

U3RhdHV0IGRlIGwnYXBwbGljYXRpb24gKEVzcGFjZXMgQ29sbGFib3JhdGlmcykgc3VyIGNv
bGxhYi1hcHAxLmluLmFjLXN0cmFzYm91cmcuZnIgLi4uIBtbMTszMm1Ew6ltYXJyw6llG1sw
OzM5bSAocGlkIDogMjUwOCkKU3RhdHV0IGRlIGwnYXBwbGljYXRpb24gKEVzcGFjZXMgQ29s
bGFib3JhdGlmcykgc3VyIGNvbGxhYi1hcHAyLmluLmFjLXN0cmFzYm91cmcuZnIgLi4uIBtb
MTszMm1Ew6ltYXJyw6llG1swOzM5bSAocGlkIDogMTc0MikK

 

c'est un serveur redhat

 

echo 'test mail' | mail -v -s 'statut' toto@pluton.com

résultat ok dans le mail : test mail

 

U3RhdHV0IGRlIGwnYXBwbGljYXRpb24gKEVzcGFjZXMgQ29sbGFib3JhdGlmcykgc3VyIGNv
bGxhYi1hcHAxLmluLmFjLXN0cmFzYm91cmcuZnIgLi4uIBtbMTszMm1Ew6ltYXJyw6llG1sw
OzM5bSAocGlkIDogMjUwOCkKU3RhdHV0IGRlIGwnYXBwbGljYXRpb24gKEVzcGFjZXMgQ29s
bGFib3JhdGlmcykgc3VyIGNvbGxhYi1hcHAyLmluLmFjLXN0cmFzYm91cmcuZnIgLi4uIBtb
MTszMm1Ew6ltYXJyw6llG1swOzM5bSAocGlkIDogMTc0MikK

sont dans le fichier source

Posté(e)
Il y a 15 heures, jakol a écrit :

J'ai des caractères illisibles pour la commande

U3RhdHV0IGRlIGwnYXBwbGljYXRpb24gKEVzcGFjZXMgQ29sbGFib3JhdGlmcykgc3VyIGNv bGxhYi1hcHAxLmluLmFjLXN0cmFzYm91cmcuZnIgLi4uIBtbMTszMm1Ew6ltYXJyw6llG1sw OzM5bSAocGlkIDogMjUwOCkKU3RhdHV0IGRlIGwnYXBwbGljYXRpb24gKEVzcGFjZXMgQ29s bGFib3JhdGlmcykgc3VyIGNvbGxhYi1hcHAyLmluLmFjLXN0cmFzYm91cmcuZnIgLi4uIBtb MTszMm1Ew6ltYXJyw6llG1swOzM5bSAocGlkIDogMTc0MikK

Ca ressemble un un encodage base 64 (utilisé par les mails par défaut pour les fichiers binaires).

Et si on revient au 

cat statutappli.txt | mail -s 'statut appli' 'toto@pluton.com'

Ca marche?

Et en créant un fichier "statutappli.txt" avec le teste 'hello world' dedans, ça marche? Parce que j'ai vraiment l'impression que ton fichier "statutappli' ne contient pas que du texte.

Posté(e)

:siffle: effectivement, en utilisant 1 outil en ligne base64 on a (:zarb: sous Linux il y a 1 commande ou alors utiliser OpenSSL)

 

Citer

Statut de l'application (Espaces Collaboratifs) sur collab-app1.in.ac-strasbourg.fr ... [1;32mDémarrée[0;39m (pid : 2508)
Statut de l'application (Espaces Collaboratifs) sur collab-app2.in.ac-strasbourg.fr ... [1;32mDémarrée[0;39m (pid : 1742)


 

Posté(e)
Il y a 2 heures, brice.wernet a écrit :

Ca ressemble un un encodage base 64 (utilisé par les mails par défaut pour les fichiers binaires).

Et si on revient au 


cat statutappli.txt | mail -s 'statut appli' 'toto@pluton.com'

Ca marche?

Et en créant un fichier "statutappli.txt" avec le teste 'hello world' dedans, ça marche? Parce que j'ai vraiment l'impression que ton fichier "statutappli' ne contient pas que du texte.

Oui ça marche quand tu intègres du texte.

Posté(e)
Il y a 2 heures, foetus a écrit :

:siffle: effectivement, en utilisant 1 outil en ligne base64 on a (:zarb: sous Linux il y a 1 commande ou alors utiliser OpenSSL

Le [1,32m me fait penser à du code de VT100.

On peut avoir le fichier txt? Je soupçonne vraiment qu'il y a des caractères spéciaux dedans (genre eof)

Posté(e)

Bonjour,

sur chaque ligne il y a les caractères  "^[".

Je les ai virés manuellement et testé l'envoi. Le texte est bien affiché dans le corps du mail

Comment supprimer ces caractère ?

Merci

Posté(e)
echo 'azerty^[qsdfgh' | sed 's/\^\[//g'

Cela me donne:

azertyqsdfgh

 

Si cela te fait bien pareil, teste ceci :

sed 's/\^\[//g' statutappli.txt | mail -s 'statut appli' 'toto@pluton.com'

 

Posté(e)

Merci malheureusement "^[" les caractères bleus ne sont pas remplacé par l'espace

image.png.741acae8b83f4681a8cc97194b566ed5.png

y a t-il de supprimer les couleurs (le bleu),?

Merci

 

Posté(e)
sed 's/\x1b//g'

Ton caractère de couleur est 1b en hexadécimal. Il suffit de le supprimer via sed

 

Sur mac, il faut faire comme ceci :

sed $'s/\x1b//g'

 

Avant le sed :

1659198334_Capturedecran2021-03-15a19_58_34.thumb.png.92d086a18dfe6392716eb006607291d6.png

Après :

1505459189_Capturedecran2021-03-15a19_58_39.thumb.png.a9948d0ee8587245046bc2b0d49fdf0e.png

 

C'est cette série de caractères qui correspond à la couleur + le [1;32m

1b 5b 31 3b 33 32 6d

 

Posté(e)

Super. Ca marche! Merci beaucoup !!

j'ai fait ça:

sed 's/\x1b//g' statutCollab.txt | mail -s "Vérifications du Statut de Collab" toto@pluton.com

 

j'ai ça comme résultat dans le mail

 

image.png.1ddb631af755f292c948473e867936c3.png

 

 

Par contre, est-ce qu'on peut virer le "[1;32m" et "[0;39m" ?

j'ai fait:

sed 's/\x1b//g' statutCollab.txt && && sed 's/\[1;32m//g' statutCollab.txt | mail -s "Vérifications du Statut de Collab" toto@pluton.com

sed 's/\x1b//g' statutCollab.txt | sed 's/\[1;32m//g' statutCollab.txt | mail -s "Vérifications du Statut de Collab" toto@pluton.com

Mais cela fonctionne pas.

Merci beaucoup. J'apprends grâce à toi !

 

 

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

×
×
  • Créer...