IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Génération d'un fichier .txt à partir de différents fichiers [Batch]


Sujet :

Scripts/Batch

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Avril 2020
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Technicien réseau

    Informations forums :
    Inscription : Avril 2020
    Messages : 4
    Par défaut Génération d'un fichier .txt à partir de différents fichiers
    Bonjour à tous,

    J'utilise aujourd'hui un script de cette forme:

    Code Batch : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    @echo off
    for /f %%a in (liste_pc.txt) do call :Commande %%a
    :Commande
    if not exist liste_pc.txt goto:eof
    set pc=%1
    if {%pc%}=={} goto:eof
    echo		host SFx%pc%>> liste_dhcp.txt
    echo						{>>liste_dhcp.txt
    echo				hardware ethernet 00:00:00:00:00:00;>>liste_dhcp.txt
    echo				fixed-address 192.162.100.%pc%;>>liste_dhcp.txt
    echo						}>>liste_dhcp.txt
    echo		host PCx%pc%>> liste_dhcp.txt
    echo						{>>liste_dhcp.txt
    echo				hardware ethernet 00:00:00:00:00:00;>>liste_dhcp.txt
    echo				fixed-address 192.168.200.%pc%;>>liste_dhcp.txt
    echo						}>>liste_dhcp.txt
    echo.>> liste_dhcp.txt


    A coté de cela j'ai un fichier liste_pc.txt comme cela:
    11
    12
    13
    14
    15
    16
    17
    18
    19

    Cela me génère un fichier final liste_dhcp.txt ainsi:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    	host SFx11
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.100.11;
    					}
    	host PCx11
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.200.11;
    					}
    
    	host SFx12
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.100.12;
    					}
    	host PCx12
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.200.12;
    					}
    
    	host SFx13
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.100.13;
    					}
    	host PCx13
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.200.13;
    					}
    
    	host SFx14
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.100.14;
    					}
    	host PCx14
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.200.14;
    					}
    
    	host SFx15
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.100.15;
    					}
    	host PCx15
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.200.15;
    					}
    
    	host SFx16
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.100.16;
    					}
    	host PCx16
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.200.16;
    					}
    
    	host SFx17
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.100.17;
    					}
    	host PCx17
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.200.17;
    					}
    
    	host SFx18
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.100.18;
    					}
    	host PCx18
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.200.18;
    					}
    
    	host SFx19
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.100.19;
    					}
    	host PCx19
    					{
    			hardware ethernet 00:00:00:00:00:00;
    			fixed-address 192.168.200.19;
    					}


    J'ai besoin de modifier ce script afin d'y incorporer automatiquement un listing de Mac-Adresses mais celui ci serait nommé par exemple liste_mac.txt contenant
    00:00:00:00:00:01
    00:00:00:00:00:02
    .....
    Il faudrait que les deux premières MAC soient insérées telle que:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
           host SFx11
    					{
    			hardware ethernet 00:00:00:00:00:01;
    			fixed-address 192.168.100.11;
    					}
    	host PCx11
    					{
    			hardware ethernet 00:00:00:00:00:02;
    			fixed-address 192.168.200.11;
    					}
    puis

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    	host SFx12
    					{
    			hardware ethernet 00:00:00:00:00:03;
    			fixed-address 192.168.100.12;
    					}
    	host PCx12
    					{
    			hardware ethernet 00:00:00:00:00:04;
    			fixed-address 192.168.200.12;
    					}

    Bien sur toutes ces adresses ne se suivent pas et il faut réellement faire appel aux deux premières valeurs puis au deux secondes ect...

    Je suis un peu perdu, auriez vous des pistes ?
    Merci d'avance,

    Cordialement,

  2. #2
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 218
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable déploiement (SCCM, InTune, GPO)
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3 218
    Par défaut
    1 seul fichier d'entré serais beaucoup mieux au niveau code et gestion pour toi.

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Avril 2020
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Technicien réseau

    Informations forums :
    Inscription : Avril 2020
    Messages : 4
    Par défaut
    Je viens d'utiliser notepad++ et j'ai transformé mes deux fichiers en 1 seul fichier , chaque élément séparé par des ";"

    Me reste a trouver la formule pour utiliser les différents éléments au bon endroit


    11;00:00:00:00:00:01;00:00:00:00:00:02
    12;00:00:00:00:00:03;00:00:00:00:00:04
    13;00:00:00:00:00:05;00:00:00:00:00:06
    .....

  4. #4
    Futur Membre du Club
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Avril 2020
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Technicien réseau

    Informations forums :
    Inscription : Avril 2020
    Messages : 4
    Par défaut
    j'en suis arrivé à ce script:

    Code Batch : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    @echo off
     
    for /f "tokens=1-3" %%a in (liste.txt ^< %liste%) do (
    set pc=%%a
    set macsf=%%b
    set mac=%%c
    )
     
    :Commande
    if not exist liste.txt goto:eof
     
     
    echo		host SFx%pc%>> liste_dhcp.txt
    echo						{>>liste_dhcp.txt
    echo				hardware ethernet %macsf%;>>liste_dhcp.txt
    echo				fixed-address 192.168.100.%pc%;>>liste_dhcp.txt
    echo						}>>liste_dhcp.txt
    echo		host PCx%pc%>> liste_dhcp.txt
    echo						{>>liste_dhcp.txt
    echo				hardware ethernet %mac%;>>liste_dhcp.txt
    echo				fixed-address 192.168.200.%pc%;>>liste_dhcp.txt
    echo						}>>liste_dhcp.txt
    echo.>> liste_dhcp.txt

    Ça fonctionne bien sur un fichier liste ou pour chaque ligne il y a un espace qui sépare les 3 éléments.

    Par contre cela ne me sort que la dernière ligne et pas celles avant.

    Comment faire pour qu'il affiche ça pour toutes les lignes?

  5. #5
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 218
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable déploiement (SCCM, InTune, GPO)
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3 218
    Par défaut
    Je ferais comme ceci

    Code batch : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    if not exist "liste.txt" goto :eof
     
    for /f "tokens=1-3 delims=;" %%a in (liste.txt) do (
    	echo host SFx%%~a
    	echo {
    	echo hardware ethernet %%~b;
    	echo fixed-address 192.162.100.%%~a;
    	echo }
    	echo host PCx%%~a
    	echo {
    	echo hardware ethernet %%~c;
    	echo fixed-address 192.168.200.%%~a;
    	echo }
    	echo.
    )>>liste_dhcp.txt

    liste.txt
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    11;00:00:00:00:00:01;00:00:00:00:00:02
    12;00:00:00:00:00:03;00:00:00:00:00:04
    13;00:00:00:00:00:05;00:00:00:00:00:06

  6. #6
    Futur Membre du Club
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Avril 2020
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Technicien réseau

    Informations forums :
    Inscription : Avril 2020
    Messages : 4
    Par défaut
    Bonjour,

    Un grand merci ericlm128 !!

    Effectivement, de cette façon, ca fonctionne parfaitement.
    Je ne connaissais pas l'utilisation du "~" !

    Top, merci beaucoup pour ta disponibilité et ton savoir faire.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [SP-2010] Generation d'un fichier Excel à partir de valeurs d'une liste SP
    Par Quinn Malory dans le forum SharePoint
    Réponses: 10
    Dernier message: 30/06/2011, 15h24
  2. [Batch] Modifier des lignes dans un .txt a partir d'un fichier .txt model
    Par AlBombar dans le forum Scripts/Batch
    Réponses: 2
    Dernier message: 21/04/2010, 17h59
  3. Réponses: 5
    Dernier message: 29/03/2007, 13h09
  4. generer un fichier txt a partir d'un formulaire php
    Par ouabi dans le forum Langage
    Réponses: 2
    Dernier message: 13/02/2006, 19h15
  5. Réponses: 18
    Dernier message: 08/08/2005, 20h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo