besoin d'un coup de main pour un script
Reccueillir une donnée et l'insérer dans un fichier.
Système et matériels / Installation et configuration

thierryR Membre non connecté
-
- Voir le profil du membre thierryR
- Inscrit le : 02/02/2010
- Site internet
Il s'agit de récupérer une donnée envoyée par mail et l'insérer dans un fichier.
Voila ce que j'ai fait:
J'utilise thunderbird et pas un googlemail car je suis incompétent pour aller chercher des datas chez google.
Dans thunderbird j'ai créé un dossier spécial pour la réception de mon message automatique Mais comme thunderbird peut changer le nom de dossier après une réinstallation, je procède ainsi:
Code BASH :
chemin=$(find /home/moi/.thunderbird -name raspberry)
ensuite je veux lire le fichier hosts
Code BASH :
old-ip = cat /etc/hosts |grep Sauvegarde|sed 's/.* {[0-9]{2}.[0-9]{2}.[0-9]{2}.[0-9]{2} } /1/' # bash: old-ip : commande introuvable sed: -e expression n°1, caractère 56: Échec du pairage de {
L'expression doit être mauvaise car mon fichier peut contenir cette ligne
Citation :
77.192.86.107 Sauvegarde
Puis je recherche $old_ip dans mon fichier
Code BASH :
cde=$(cat $chemin | grep $old_ip)
Ce qui doit me ressortir ma derniere ligne à savoir:
Code BASH :
s/86.66.218.60/86.66.183.123/g
Puis il ne me reste plus qu'à faire la mise à jour en root:
Code BASH :
sed -e "$cde" -i /etc/hosts;
Si le root execute ce script dans une tâche cron, il ne devrait y avoir de souci.
Merci aux spécialistes de la ligne de Cde.
débusqueur de bugs et chercheur en améliorations
Amicalement vôtre.
Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller

Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller

Adrien.D Membre non connecté
-
- Voir le profil du membre Adrien.D
- Inscrit le : 30/05/2011
- Site internet
- Groupes :
Code BASH :
old-ip = cat /etc/hosts |grep Sauvegarde|sed 's/.* {[0-9]{2}.[0-9]{2}.[0-9]{2}.[0-9]{2} } /1/' #
NON
Code BASH :
old-ip=$(cat /etc/hosts |grep Sauvegarde|sed 's/.* {[0-9]{2}.[0-9]{2}.[0-9]{2}.[0-9]{2} } /1/' )
Mais attention, une IP peut avoir 2 chiffres ou 3 ou 1
Donc l'expression régulière pourrait être :
Code BASH :
([0-9]{1,3}.){3}[0-9]{1,3}
Config : PC Fixe : X470 GAMING PRO- AMD Ryzen 5 2600X - 16Go RAM - Radeon RX 560 (Pilote libre) - Gentoo Linux - GNOME Desktop - Kernel 5.10 LTS
Ancien Webmaster de MageiaLinuxOnline. Les remplaçants assurent !
Ancien Webmaster de MageiaLinuxOnline. Les remplaçants assurent !


thierryR Membre non connecté
-
- Voir le profil du membre thierryR
- Inscrit le : 02/02/2010
- Site internet
débusqueur de bugs et chercheur en améliorations
Amicalement vôtre.
Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller

Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller

thierryR Membre non connecté
-
- Voir le profil du membre thierryR
- Inscrit le : 02/02/2010
- Site internet
Code BASH :
sed 's/([0-9]{1,3}.){3}[0-9]{1,3}//' 77.192.86.107 Sauvegarde
Code BASH :
sed 's/([0-9]{1,3}.){3}[0-9]{1,3}/ 1/' 77.192.86.107 Sauvegarde
Code BASH :
sed 's/([0-9]{1,3}.){3}[0-9]{1,3}/1/' sed: -e expression n°1, caractère 33: référence 1 invalide dans le côté droit de la commande `s'
Si c'est impossible, il me faudra tronquer la variable. Je devrai utiliser un truc comme "cut -d -f1" ,
Qu'en penses tu ?
débusqueur de bugs et chercheur en améliorations
Amicalement vôtre.
Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller

Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller

Adrien.D Membre non connecté
-
- Voir le profil du membre Adrien.D
- Inscrit le : 30/05/2011
- Site internet
- Groupes :

Code BASH :
12 [21:47:46] adrien@superlinux: ~ $ grep -Eo '([0-9]{1,3}.){3}[0-9]{1,3}' /etc/hosts 127.0.0.1
Et 1 commande au lieu de 3 c'est plus performant

Config : PC Fixe : X470 GAMING PRO- AMD Ryzen 5 2600X - 16Go RAM - Radeon RX 560 (Pilote libre) - Gentoo Linux - GNOME Desktop - Kernel 5.10 LTS
Ancien Webmaster de MageiaLinuxOnline. Les remplaçants assurent !
Ancien Webmaster de MageiaLinuxOnline. Les remplaçants assurent !


thierryR Membre non connecté
-
- Voir le profil du membre thierryR
- Inscrit le : 02/02/2010
- Site internet
Code BASH :
grep -Eo '([0-9]{1,3}.){3}[0-9]{1,3}' /etc/hosts 127.0.0.1 192.168.1.86 77.192.86.107

Édité par thierryR Le 22/12/2015 à 23h29
débusqueur de bugs et chercheur en améliorations
Amicalement vôtre.
Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller

Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller

Adrien.D Membre non connecté
-
- Voir le profil du membre Adrien.D
- Inscrit le : 30/05/2011
- Site internet
- Groupes :
Pas de balise bash je suis avec le tel c'est pas pratique.
Je ne peux donc pas tester mais ça doit être bon...
Config : PC Fixe : X470 GAMING PRO- AMD Ryzen 5 2600X - 16Go RAM - Radeon RX 560 (Pilote libre) - Gentoo Linux - GNOME Desktop - Kernel 5.10 LTS
Ancien Webmaster de MageiaLinuxOnline. Les remplaçants assurent !
Ancien Webmaster de MageiaLinuxOnline. Les remplaçants assurent !


thierryR Membre non connecté
-
- Voir le profil du membre thierryR
- Inscrit le : 02/02/2010
- Site internet
Code BASH :
grep -Eo '([0-9]{1,3}.){3}[0-9]{1,3}' /etc/hosts | grep -v '(^127|^192)' 127.0.0.1 192.168.1.86 77.192.86.107
Édité par thierryR Le 22/12/2015 à 23h40
débusqueur de bugs et chercheur en améliorations
Amicalement vôtre.
Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller

Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller

Adrien.D Membre non connecté
-
- Voir le profil du membre Adrien.D
- Inscrit le : 30/05/2011
- Site internet
- Groupes :
Code BASH :
grep Sauvegarde /etc/hosts | grep -Eo '([0-9]{1,3}.){3}[0-9]{1,3}'
Config : PC Fixe : X470 GAMING PRO- AMD Ryzen 5 2600X - 16Go RAM - Radeon RX 560 (Pilote libre) - Gentoo Linux - GNOME Desktop - Kernel 5.10 LTS
Ancien Webmaster de MageiaLinuxOnline. Les remplaçants assurent !
Ancien Webmaster de MageiaLinuxOnline. Les remplaçants assurent !


thierryR Membre non connecté
-
- Voir le profil du membre thierryR
- Inscrit le : 02/02/2010
- Site internet


débusqueur de bugs et chercheur en améliorations
Amicalement vôtre.
Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller

Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller

Adrien.D Membre non connecté
-
- Voir le profil du membre Adrien.D
- Inscrit le : 30/05/2011
- Site internet
- Groupes :

Config : PC Fixe : X470 GAMING PRO- AMD Ryzen 5 2600X - 16Go RAM - Radeon RX 560 (Pilote libre) - Gentoo Linux - GNOME Desktop - Kernel 5.10 LTS
Ancien Webmaster de MageiaLinuxOnline. Les remplaçants assurent !
Ancien Webmaster de MageiaLinuxOnline. Les remplaçants assurent !


thierryR Membre non connecté
-
- Voir le profil du membre thierryR
- Inscrit le : 02/02/2010
- Site internet

débusqueur de bugs et chercheur en améliorations
Amicalement vôtre.
Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller

Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller

zalappy Membre non connecté
-
- Voir le profil du membre zalappy
- Inscrit le : 28/07/2012
- Groupes :
<table class="formatter-table">
<tr class="formatter-table-row">
<td class="formatter-table-col">Mageia7.1/6/5-64bits-Xfce</td>
<td class="formatter-table-col">Demander la maj d'un prog existant du CCM.</td>
<td class="formatter-table-col">[Tuto] Configuration d'un serveur LAMP</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">[Tuto] installer VeraCrypt.</td>
<td class="formatter-table-col">Cloner un disque, une partition</td>
<td class="formatter-table-col">Thèmes icônes xfce/plasma les modifiées</td>
</tr>
</table>
<tr class="formatter-table-row">
<td class="formatter-table-col">Mageia7.1/6/5-64bits-Xfce</td>
<td class="formatter-table-col">Demander la maj d'un prog existant du CCM.</td>
<td class="formatter-table-col">[Tuto] Configuration d'un serveur LAMP</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">[Tuto] installer VeraCrypt.</td>
<td class="formatter-table-col">Cloner un disque, une partition</td>
<td class="formatter-table-col">Thèmes icônes xfce/plasma les modifiées</td>
</tr>
</table>

thierryR Membre non connecté
-
- Voir le profil du membre thierryR
- Inscrit le : 02/02/2010
- Site internet
débusqueur de bugs et chercheur en améliorations
Amicalement vôtre.
Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller

Kernel: 4.4.92-desktop-1.mga5 x86_64 (64 bit) Desktop: KDE 4.14.35 Distro: Mageia 5 thornicroft
Machine: Mobo: ASUSTeK model: X751SA v: 1.0 Bios: American Megatrends v: X751SA.403
CPU: Quad core Intel Pentium N3710 (-MCP-) cache: 1024 KB Graphics: Card: Intel Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller
Répondre
Vous n'êtes pas autorisé à écrire dans cette catégorie