|
|
|
|
Bonjour,
-------
J'ai un fichier "toto.txt" dont le contenu est: "ceci est un exemple"
Je souhaiterais a l'aide d'un bash:
Rediriger le contenu de "toto.txt" dans une variable et dire
si cette variable est = "ceci est un exemple" alors envoyer
un mail sinon ne rien faire.
(mon but est d'envoyer un mail si le contenu d'un fichier texte change).
Merci de votre aide,
climbing31@gmail.com
Explique clairement ce que tu veux faire :
|
D'accord pour plus de précision ;-)
Configuration: Windows XP Internet Explorer 7.0 |
Il y a sûrement d'autres façons de faire, en voilà une : [tmpfs]$ cat toto.txt je m'appelle toto je m'appelle tutu je m'appelle titi [tmpfs]$ cat origan31.sh #! /bin/bash # set -xv head -1 "$1" | grep "$2" >/dev/null if [ "$?" == 0 ] then echo "La 1ère ligne contient bien : $2" else echo "La 1ère ligne ne contient pas : $2" fi [tmpfs]$ ./origan31.sh toto.txt "je m'appelle toto" La 1ère ligne contient bien : je m'appelle toto [tmpfs]$ ./origan31.sh toto.txt "je m'appelle momo" La 1ère ligne ne contient pas : je m'appelle momo [tmpfs]$;-)) Z'@+...che. JP : Zen, my Nuggets ! ;-) Le savoir n'est bon que s'il est partagé. |
Merci beaucoup Jipicy pour cette réponse,
Configuration: Windows XP Internet Explorer 7.0 |
[tmpfs]$ cat toto.txt
la température est de 28 degrés celcius
je m'appelle toto
je m'appelle tutu
je m'appelle titi
[tmpfs]$ cat origan31.sh
#! /bin/bash
# set -xv
temp=$(head -1 $1 | egrep -o "[0-9]{2}")
if [ "$temp" -gt 25 ]
then
echo "Attention la température excède les 25° !!! "
fi
[tmpfs]$ ./origan31.sh toto.txt
Attention la température excède les 25° !!!
[tmpfs]$ ;-))
Z'@+...che. JP : Zen, my Nuggets ! ;-) Le savoir n'est bon que s'il est partagé. |
Merci beaucoup !! ca marche presque (je me débrouillerais ensuite pour envoyer le résultat par mail)
Configuration: Windows XP Internet Explorer 7.0 |
Super merci Jipicy ! ca marche ;-)
Configuration: Windows XP Internet Explorer 7.0 |