Edition de fichier en script bash

Résolu
sbouli Messages postés 208 Statut Membre -  
jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   -
Bonjour,

J'ai petit à petit développé un script bash d'install de machine pour des machines d'un même type, mais je suis confronté à un petit soucis qui m'oblige à scinder mon script en plusieur parties pour entrecaller des interventions "humaines".
Par exemple, je dois editer le fichier /etc/default/rsync pour modifier 2 lignes
RSYNC_ENABLE=
et
RSYNC_CONFIG_FILE=

or je ne vois pas comment faire pour juste mettre à jour ces 2 lignes, si je pouvais dire remplace la ligne contenant RSYNC_ENABLE= par RSYNC_ENABLE=true ce serait déjà nickel.

un autre exemple :
le fichier /etc/postfix/master.cf
je dois modifier le fichier en plusieurs endroit mais sur des colonnes précises, genre remplacer l'avant dernier "-" d'une ligne par "500" ...
comment faire ?

En vous remerciant.

Stéphane

11 réponses

  1. jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   4 898
     
    Salut,

    Et pour ton histoire d'avant-dernier champ :
    jp@MDK:~/tmpfs ssh$ cat plop
    blablabla
    blablabl
    blablabla
    blablalba
    RSYNC_ENABLE=
    blablabla
    blablabla
    blablabla
    bla-bla-bla-bla-bla-bla-bla-bla-bla
    
    jp@MDK:~/tmpfs ssh$ sed 's/RSYNC_ENABLE=/&true/; s/\(.*\)-\(.*-\)/\1BLA\2/' plop
    blablabla
    blablabl
    blablabla
    blablalba
    RSYNC_ENABLE=true
    blablabla
    blablabla
    blablabla
    bla-bla-bla-bla-bla-bla-blaBLAbla-bla
    
    jp@MDK:~/tmpfs ssh$
    Bobby : Je me suis permis d'optimiser ta syntaxe ;-))
    1
    1. bob031 Messages postés 8228 Statut Membre 473
       
      mais tu as bien fait et j'en attendais pas moins.

      :-))
      0
  2. jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   4 898
     
    Tu rajouteras le "-i.bak" si tu vois que ça passe bien...
     sed '
    s/^\*\.\*;auth,authpriv.none/&,mail\.none/
    /^mail\.\(\* \|info \|warn \|err\)/ s/var/home/
    ' syslog
    1
    1. sbouli Messages postés 208 Statut Membre 2
       
      J'ai juste sorti les espaces après info et warn et c'est nickel. j'avais pas pris suffisamment de recul là ... ridicule. Quelle puissance les expressions régulières ...

      Bon, je poursuis mon script.

      Merci beaucoup.

      Stéphane
      0
      1. jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   4 898 > sbouli Messages postés 208 Statut Membre
         
        Oups j'avions aussi oublié de les retirer (les espaces) ;-((

        De rien ;-)
        0
  3. kiki
     
    Pour remplacer une expression on effectue une substitution.
    j'ai vu ça en perl il y a un paquet d'années...

    http://esbs.unistra.fr/

    s/RSYNC_ENABLE=/RSYNC_ENABLE=true/

    Dans cet exercice est indiqué comment crrer un tableau à partir d'un séparateur
    http://esbs.unistra.fr/#exo1

    @tab=split(' ',$string)

    Comme le nombre de colonne dans le fichier master.cf est fixe c'est pas trop compliqué
    dans cet exemple, la 7e colonne sera $tab[6]="-" (on démarre à zero)

    perl c'est trés puissant pour manipuler des données, ca vaut le coup de s'y pencher si ce genre de problème revient souvent.

    On trouve plei de cours universitaires :
    http://www.med.univ-rennes1.fr/~poulique/cours/perl/perl_html/introperl.html
    ou autre :
    https://formation-perl.fr/guide-perl.html
    0
  4. bob031 Messages postés 8228 Statut Membre 473
     
    Bonjour,

    une piste avec sed :
    > redfox@mandriva[192.168.1.2]:~$ cat essaiscript
    blablabla
    blablabl
    blablabla
    blablalba
    RSYNC_ENABLE=
    blablabla
    blablabla
    blablabla
    > redfox@mandriva[192.168.1.2]:~$
    > redfox@mandriva[192.168.1.2]:~$ sed -i 's/RSYNC_ENABLE=/RSYNC_ENABLE=true/' essaiscript
    > redfox@mandriva[192.168.1.2]:~$ cat essaiscript
    blablabla
    blablabl
    blablabla
    blablalba
    RSYNC_ENABLE=true
    blablabla
    blablabla
    blablabla
    > redfox@mandriva[192.168.1.2]:~$ 
    0
  5. Vous n’avez pas trouvé la réponse que vous recherchez ?

    Posez votre question
  6. sbouli Messages postés 208 Statut Membre 2
     
    Merci à tous,

    je test tout ça asap ... surtout que j'ai déjà bricoler un parser de log en perl avec beaucoup d'aide de jipicy ...

    Stéphane
    0
  7. sbouli Messages postés 208 Statut Membre 2
     
    Bonjour,

    Finalement je ne m'en sors pas, je vous détail la tâche qui vous semblera surement simplicime ... :

    J'ai le fichier de conf par défaut de postfix suivant : /etc/postfix/master.cf

    #
    # Postfix master process configuration file.  For details on the format
    # of the file, see the master(5) manual page (command: "man 5 master").
    #
    # Do not forget to execute "postfix reload" after editing this file.
    #
    # ==========================================================================
    # service type  private unpriv  chroot  wakeup  maxproc command + args
    #               (yes)   (yes)   (yes)   (never) (100)
    # ==========================================================================
    smtp      inet  n       -       -       -        -      smtpd
    #submission inet n       -       -       -       -       smtpd
    #  -o smtpd_tls_security_level=encrypt
    #  -o smtpd_sasl_auth_enable=yes
    #  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
    #  -o milter_macro_daemon_name=ORIGINATING
    #smtps     inet  n       -       -       -       -       smtpd
    #  -o smtpd_tls_wrappermode=yes
    #  -o smtpd_sasl_auth_enable=yes
    #  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
    #  -o milter_macro_daemon_name=ORIGINATING
    #628      inet  n       -       -       -       -       qmqpd
    pickup    fifo  n       -       -       60      1       pickup
    cleanup   unix  n       -       -       -       0       cleanup
    qmgr      fifo  n       -       n       300     1       qmgr
    #qmgr     fifo  n       -       -       300     1       oqmgr
    tlsmgr    unix  -       -       -       1000?   1       tlsmgr
    rewrite   unix  -       -       -       -       -       trivial-rewrite
    bounce    unix  -       -       -       -       0       bounce
    defer     unix  -       -       -       -       0       bounce
    trace     unix  -       -       -       -       0       bounce
    verify    unix  -       -       -       -       1       verify
    flush     unix  n       -       -       1000?   0       flush
    proxymap  unix  -       -       n       -       -       proxymap
    proxywrite unix -       -       n       -       1       proxymap
    smtp      unix  -       -       -       -       -       smtp
    
    
    # When relaying mail as backup MX, disable fallback_relay to avoid MX loops
    relay     unix  -       -       -       -       -       smtp
            -o smtp_fallback_relay=
    #       -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
    showq     unix  n       -       -       -       -       showq
    error     unix  -       -       -       -       -       error
    retry     unix  -       -       -       -       -       error
    discard   unix  -       -       -       -       -       discard
    local     unix  -       n       n       -       -       local
    virtual   unix  -       n       n       -       -       virtual
    lmtp      unix  -       -       -       -       -       lmtp
    anvil     unix  -       -       -       -       1       anvil
    scache    unix  -       -       -       -       1       scache
    #
    # ====================================================================
    # Interfaces to non-Postfix software. Be sure to examine the manual
    # pages of the non-Postfix software to find out what options it wants.
    #
    # Many of the following services use the Postfix pipe(8) delivery
    # agent.  See the pipe(8) man page for information about ${recipient}
    # and other message envelope options.
    # ====================================================================
    #
    # maildrop. See the Postfix MAILDROP_README file for details.
    # Also specify in main.cf: maildrop_destination_recipient_limit=1
    #
    maildrop  unix  -       n       n       -       -       pipe
      flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
    #
    # See the Postfix UUCP_README file for configuration details.
    #
    uucp      unix  -       n       n       -       -       pipe
      flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
    #
    # Other external delivery methods.
    #
    ifmail    unix  -       n       n       -       -       pipe
      flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
    bsmtp     unix  -       n       n       -       -       pipe
      flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
    scalemail-backend unix  -       n       n       -       2       pipe
      flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
    mailman   unix  -       n       n       -       -       pipe
      flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
      ${nexthop} ${user}
    


    et je veux :

    1 - paramétrer 2 lignes :

    smtp      inet  n       -       -       -       20      smtpd
    smtp      unix  -       -       -       -       30       smtp
    


    2 - insérer 2 lignes entre les lignes :

    	scache    unix  -       -       -       -       1       scache
    	#
    	# ====================================================================
    


    sous la forme
    	scache    unix  -       -       -       -       1       scache
    	yahoo_tr  unix  -       -       n       -       5      smtp
    	hotmail_tr unix -       -       n       -       5      smtp
    	#
    	# ====================================================================
    


    Comment préciser à sed, quelle lignes modifier ? comment insérer des lignes ?

    Merci pour votre aide.

    Stéphane
    0
  8. jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   4 898
     
    Re-

    Essaye ça :
    jp@MDK:~/tmpfs ssh$ cat prog.sed
    /^smtp inet/{
    s/\(.*\)-/\120/
    }
    /^smtp unix/{
    s/\(.*\)-/\130/
    }
    /^scache/a\
    yahoo_tr  unix  -       -       n       -       5      smtp\
    hotmail_tr unix -       -       n       -       5      smtp
    
    jp@MDK:~/tmpfs ssh$ sed -i.bak -f prog.sed plop
    


    Le fichier "plop" chez moi est une copie de ton "master.cf".
    Et voilà les différences entre "plop" et "plop.bak" :
    jp@MDK:~/tmpfs ssh$ diff plop plop.bak
    11c11
    < smtp inet n - - - 20 smtpd
    ---
    > smtp inet n - - - - smtpd
    36c36
    < smtp unix - - - - 30 smtp
    ---
    > smtp unix - - - - - smtp
    52,53d51
    < yahoo_tr  unix  -       -       n       -       5      smtp
    < hotmail_tr unix -       -       n       -       5      smtp
    
    jp@MDK:~/tmpfs ssh$
    ;-))
    0
    1. sbouli Messages postés 208 Statut Membre 2
       
      bon ... j'ai honte mais ...

      Je souhaite avoir les commandes dans le script principal par un sous script sed (fichier prog.sed)

      je pensais pouvoir faire :

      set '/^smtp inet/{ s/\(.*\)-/\120/' /etc/postfix/master.cf

      ça ne renvois pas d'erreur mais ne modifie pas le fichier ... est-ce lié aux espaces entre smtp et inet ?

      Stéphane
      0
    2. jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   4 898 > sbouli Messages postés 208 Statut Membre
       
      Pour qu'un fichier soit modifié "en place" il faut ajouter l'option "-i" (in place) à la commande "sed", éventuellement y adjoindre une option de sauvegarde du fichier "-i.bak".

      Par contre, effectivement si c'est des tabulations et non des espaces qu'il y a entre "smtp" et "unix/inet", il faut soit écrire :
      /^smtp      inet/
      ou
      /^smtp *inet/

      Essaie comme ça dans ton script :
      sed -i.bak '
      /^smtp      inet/{
      s/\(.*\)-/\120/
      }
      /^smtp      unix/{
      s/\(.*\)-/\130/
      }
      /^scache/a\
      yahoo_tr  unix  -       -       n       -       5      smtp\
      hotmail_tr unix -       -       n       -       5      smtp
      ' /etc/postfix/master.cf 

      0
    3. sbouli Messages postés 208 Statut Membre 2 > jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention  
       
      Bonjour,

      Je reviens vers vous car je dois modifier ce fichier encore une fois, le but jusqu'alors etait de mettre des valeurs dans les bonnes colonnes, maintenant je dois ajouter une ligne complete SOUS la ligne en question, dont je ne suis pas sûr que la position dans le fichier soit toujours la même ... et je n'ai pas toujours la même ligne en dessous :

      smtp      unix  -       -       -       -       -       smtp
      

      je veux ajouter en dessous de cette ligne (commençant par "smtp(.*)unix") :

      smtp      unix  -       -       -       -       -       smtp
                   -o smtp_bind_address='"$ipfailover"'
      


      idem plus bas :

      # When relaying mail as backup MX, disable fallback_relay to avoid MX loops
      relay     unix  -       -       -       -       -       smtp
              -o smtp_fallback_relay=
              -o smtp_bind_address='"$ipfailover"'
      


      Merci d'avance ...

      Stéphane
      0
    4. jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   4 898 > sbouli Messages postés 208 Statut Membre
       
      Ben la solution est déjà dans tes demandes précédentes :
      sed -i.bak '
      /^smtp      inet/{
      s/\(.*\)-/\120/
      }
      /^smtp      unix/{
      s/\(.*\)-/\130/
      }
      /^scache/a\
      yahoo_tr  unix  -       -       n       -       5      smtp\
      hotmail_tr unix -       -       n       -       5      smtp
      ' /etc/postfix/master.cf 
      Tout ce que tu as à faire c'est de changer le motif ("/^scache/" dans l'exemple ci-dessus), le reste de la syntaxe ne bouge pas...

      Ce qui donne :
      jp@MDK:~/tmpfs ssh$ cat plop
      #
      # Postfix master process configuration file.  For details on the format
      # of the file, see the master(5) manual page (command: "man 5 master").
      #
      # Do not forget to execute "postfix reload" after editing this file.
      #
      # ==========================================================================
      # service type  private unpriv  chroot  wakeup  maxproc command + args
      #               (yes)   (yes)   (yes)   (never) (100)
      # ==========================================================================
      smtp      inet  n       -       -       -        -      smtpd
      #submission inet n       -       -       -       -       smtpd
      #  -o smtpd_tls_security_level=encrypt
      #  -o smtpd_sasl_auth_enable=yes
      #  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
      #  -o milter_macro_daemon_name=ORIGINATING
      #smtps     inet  n       -       -       -       -       smtpd
      #  -o smtpd_tls_wrappermode=yes
      #  -o smtpd_sasl_auth_enable=yes
      #  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
      #  -o milter_macro_daemon_name=ORIGINATING
      #628      inet  n       -       -       -       -       qmqpd
      pickup    fifo  n       -       -       60      1       pickup
      cleanup   unix  n       -       -       -       0       cleanup
      qmgr      fifo  n       -       n       300     1       qmgr
      #qmgr     fifo  n       -       -       300     1       oqmgr
      tlsmgr    unix  -       -       -       1000?   1       tlsmgr
      rewrite   unix  -       -       -       -       -       trivial-rewrite
      bounce    unix  -       -       -       -       0       bounce
      defer     unix  -       -       -       -       0       bounce
      trace     unix  -       -       -       -       0       bounce
      verify    unix  -       -       -       -       1       verify
      flush     unix  n       -       -       1000?   0       flush
      proxymap  unix  -       -       n       -       -       proxymap
      proxywrite unix -       -       n       -       1       proxymap
      smtp      unix  -       -       -       -       -       smtp
      
      
      # When relaying mail as backup MX, disable fallback_relay to avoid MX loops
      relay     unix  -       -       -       -       -       smtp
              -o smtp_fallback_relay=
      #       -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
      showq     unix  n       -       -       -       -       showq
      error     unix  -       -       -       -       -       error
      retry     unix  -       -       -       -       -       error
      discard   unix  -       -       -       -       -       discard
      local     unix  -       n       n       -       -       local
      virtual   unix  -       n       n       -       -       virtual
      lmtp      unix  -       -       -       -       -       lmtp
      anvil     unix  -       -       -       -       1       anvil
      scache    unix  -       -       -       -       1       scache
      #
      # ====================================================================
      # Interfaces to non-Postfix software. Be sure to examine the manual
      # pages of the non-Postfix software to find out what options it wants.
      #
      # Many of the following services use the Postfix pipe(8) delivery
      # agent.  See the pipe(8) man page for information about ${recipient}
      # and other message envelope options.
      # ====================================================================
      #
      # maildrop. See the Postfix MAILDROP_README file for details.
      # Also specify in main.cf: maildrop_destination_recipient_limit=1
      #
      maildrop  unix  -       n       n       -       -       pipe
        flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
      #
      # See the Postfix UUCP_README file for configuration details.
      #
      uucp      unix  -       n       n       -       -       pipe
        flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
      #
      # Other external delivery methods.
      #
      ifmail    unix  -       n       n       -       -       pipe
        flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
      bsmtp     unix  -       n       n       -       -       pipe
        flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
      scalemail-backend unix  -       n       n       -       2       pipe
        flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
      mailman   unix  -       n       n       -       -       pipe
        flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
        ${nexthop} ${user}
      
      jp@MDK:~/tmpfs ssh$ sed  '/^smtp      unix/{
      a\
      \t-o smtp_bind_address=$ipfailover
      }
      /^relay     unix/n;{
      /-o smtp_fallback_relay=/{
      a\
      \t-o smtp_bind_address=$ipfailover
      }
      }
      ' plop
      #
      # Postfix master process configuration file.  For details on the format
      # of the file, see the master(5) manual page (command: "man 5 master").
      #
      # Do not forget to execute "postfix reload" after editing this file.
      #
      # ==========================================================================
      # service type  private unpriv  chroot  wakeup  maxproc command + args
      #               (yes)   (yes)   (yes)   (never) (100)
      # ==========================================================================
      smtp      inet  n       -       -       -        -      smtpd
      #submission inet n       -       -       -       -       smtpd
      #  -o smtpd_tls_security_level=encrypt
      #  -o smtpd_sasl_auth_enable=yes
      #  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
      #  -o milter_macro_daemon_name=ORIGINATING
      #smtps     inet  n       -       -       -       -       smtpd
      #  -o smtpd_tls_wrappermode=yes
      #  -o smtpd_sasl_auth_enable=yes
      #  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
      #  -o milter_macro_daemon_name=ORIGINATING
      #628      inet  n       -       -       -       -       qmqpd
      pickup    fifo  n       -       -       60      1       pickup
      cleanup   unix  n       -       -       -       0       cleanup
      qmgr      fifo  n       -       n       300     1       qmgr
      #qmgr     fifo  n       -       -       300     1       oqmgr
      tlsmgr    unix  -       -       -       1000?   1       tlsmgr
      rewrite   unix  -       -       -       -       -       trivial-rewrite
      bounce    unix  -       -       -       -       0       bounce
      defer     unix  -       -       -       -       0       bounce
      trace     unix  -       -       -       -       0       bounce
      verify    unix  -       -       -       -       1       verify
      flush     unix  n       -       -       1000?   0       flush
      proxymap  unix  -       -       n       -       -       proxymap
      proxywrite unix -       -       n       -       1       proxymap
      smtp      unix  -       -       -       -       -       smtp
              -o smtp_bind_address=$ipfailover
      
      
      # When relaying mail as backup MX, disable fallback_relay to avoid MX loops
      relay     unix  -       -       -       -       -       smtp
              -o smtp_fallback_relay=
              -o smtp_bind_address=$ipfailover
      #       -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
      showq     unix  n       -       -       -       -       showq
      error     unix  -       -       -       -       -       error
      retry     unix  -       -       -       -       -       error
      discard   unix  -       -       -       -       -       discard
      local     unix  -       n       n       -       -       local
      virtual   unix  -       n       n       -       -       virtual
      lmtp      unix  -       -       -       -       -       lmtp
      anvil     unix  -       -       -       -       1       anvil
      scache    unix  -       -       -       -       1       scache
      #
      # ====================================================================
      # Interfaces to non-Postfix software. Be sure to examine the manual
      # pages of the non-Postfix software to find out what options it wants.
      #
      # Many of the following services use the Postfix pipe(8) delivery
      # agent.  See the pipe(8) man page for information about ${recipient}
      # and other message envelope options.
      # ====================================================================
      #
      # maildrop. See the Postfix MAILDROP_README file for details.
      # Also specify in main.cf: maildrop_destination_recipient_limit=1
      #
      maildrop  unix  -       n       n       -       -       pipe
        flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
      #
      # See the Postfix UUCP_README file for configuration details.
      #
      uucp      unix  -       n       n       -       -       pipe
        flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
      #
      # Other external delivery methods.
      #
      ifmail    unix  -       n       n       -       -       pipe
        flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
      bsmtp     unix  -       n       n       -       -       pipe
        flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
      scalemail-backend unix  -       n       n       -       2       pipe
        flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
      mailman   unix  -       n       n       -       -       pipe
        flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
        ${nexthop} ${user}
      
      jp@MDK:~/tmpfs ssh$
      ;-))

      0
    5. sbouli Messages postés 208 Statut Membre 2 > jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention  
       
      Le pire c'est que j'avais réfléchis avant de poster ....

      Merci encore.

      Stéphane
      0
  9. sbouli Messages postés 208 Statut Membre 2
     
    ok, je test ça de suite,

    sinon est-il possible d'utiliser des variables dans la commande sed ?

    genre :

    sed -i 's/$variable1/$variable2 $variable1/' /plop

    ou

    sed -i 's/'+$variable1+'/'+$variable2+' '+$variable1+'/' /plop

    ???

    Stéphane
    0
    1. jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   4 898
       
      0
      1. sbouli Messages postés 208 Statut Membre 2 > jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention  
         
        ça fonctionne nickel les variables maintenant avec le '" "'

        merci
        0
  10. sbouli Messages postés 208 Statut Membre 2
     
    bon ... je galère toujours ... pourtant ça a l'air simple ... :

    j'ai un fichier syslog.conf
    #  /etc/syslog.conf     Configuration file for syslogd.
    #
    #                       For more information see syslog.conf(5)
    #                       manpage.
    
    #
    # First some standard logfiles.  Log by facility.
    #
    
    auth,authpriv.*                 /var/log/auth.log
    *.*;auth,authpriv.none          -/var/log/syslog
    #cron.*                         /var/log/cron.log
    daemon.*                        -/var/log/daemon.log
    kern.*                          -/var/log/kern.log
    lpr.*                           -/var/log/lpr.log
    mail.*                          -/var/log/mail.log
    user.*                          -/var/log/user.log
    
    #
    # Logging for the mail system.  Split it up so that
    # it is easy to write scripts to parse these files.
    #
    mail.info                       -/var/log/mail.info
    mail.warn                       -/var/log/mail.warn
    mail.err                        /var/log/mail.err
    
    # Logging for INN news system
    #
    news.crit                       /var/log/news/news.crit
    news.err                        /var/log/news/news.err
    news.notice                     -/var/log/news/news.notice
    
    #
    # Some `catch-all' logfiles.
    #
    *.=debug;\
            auth,authpriv.none;\
            news.none;mail.none     -/var/log/debug
    *.=info;*.=notice;*.=warn;\
            auth,authpriv.none;\
            cron,daemon.none;\
            mail,news.none          -/var/log/messages
    
    #
    # Emergencies are sent to everybody logged in.
    #
    *.emerg                         *
    
    #
    # I like to have messages displayed on the console, but only on a virtual
    # console I usually leave idle.
    #
    #daemon,mail.*;\
    #       news.=crit;news.=err;news.=notice;\
    #       *.=debug;*.=info;\
    #       *.=notice;*.=warn       /dev/tty8
    
    # The named pipe /dev/xconsole is for the `xconsole' utility.  To use it,
    # you must invoke `xconsole' with the `-file' option:
    #
    #    $ xconsole -file /dev/xconsole [...]
    #
    # NOTE: adjust the list below, or you'll go crazy if you have a reasonably
    #      busy site..
    #
    daemon.*;mail.*;\
            news.err;\
            *.=debug;*.=info;\
            *.=notice;*.=warn       |/dev/xconsole
    


    Je veux modifier certaines lignes :

    *.*;auth,authpriv.none,mail.none		-/var/log/syslog
    
    mail.*				-/home/log/mail.log
    
    #mail.info			-/home/log/mail.info
    mail.warn			-/home/log/mail.warn
    mail.err			/home/log/mail.err
    


    J'ai donc essayé :

    echo "syslog"
    sed -i.bak '
    /^*.*;auth,authpriv.none/{
    s/\(.*\)/\&*.*;auth,authpriv.none,mail.none          -\/var\/log\/syslog/
    }
    /^mail.*/{
    s/\(.*\)/\&mail.*                          -\/home\/log\/mail.log/
    }
    /^mail.info/{
    s/\(.*\)/\&#mail.info                       -\/home\/log\/mail.info/
    }
    /^mail.warn/{
    s/\(.*\)/\&mail.warn                       -\/home\/log\/mail.warn/
    }
    /^mail.err/{
    s/\(.*\)/\&mail.err                       \/home\/log\/mail.err/
    }
    ' /etc/syslog.conf
    


    mais ça ne fonctionne pas ... il remplace les remplacements avec l'expression mail.*

    comment escaper l'étoile comme un caractère et pas un joker ? (j'ai essayé le \ et entre " sans succès)

    Stéphane
    0
  11. jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   4 898
     
    *.*;auth,authpriv.none,mail.none		-/var/log/syslog
    
    mail.*				-/home/log/mail.log
    
    #mail.info			-/home/log/mail.info
    mail.warn			-/home/log/mail.warn
    mail.err			/home/log/mail.err
    

    Tu veux le modifier en quoi ?
    0
  12. sbouli Messages postés 208 Statut Membre 2
     
    Je veux modifier :

    *.*;auth,authpriv.none -/var/log/syslog
    en
    *.*;auth,authpriv.none,mail.none -/var/log/syslog

    mail.* -/var/log/mail.log
    en
    mail.* -/home/log/mail.log

    mail.info -/var/log/mail.info
    en
    #mail.info -/home/log/mail.info

    mail.warn -/var/log/mail.warn
    en
    mail.warn -/home/log/mail.warn

    mail.err /var/log/mail.err
    en
    mail.err /home/log/mail.err

    Stéphane
    0