Welcome to Centmin Mod Community
Register Now

Create a bash script

Discussion in 'System Administration' started by pamamolf, Jun 23, 2014.

Tags:
  1. eva2000

    eva2000 Administrator Staff Member

    44,527
    10,170
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,742
    Local Time:
    3:15 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
  2. pamamolf

    pamamolf Premium Member Premium Member

    3,811
    369
    83
    May 31, 2014
    Ratings:
    +711
    Local Time:
    8:15 PM
    Nginx-1.17.x
    MariaDB 10.3.x
    From the first check is too advance for me lol :)

    I will try with this:

    Code:
    exec "${@}" > >(tee logfile) 2>&1
    or this:

    Code:
    #!/bin/bash
    (
    # begin your commands
    .
    .
    .
    # end your commands
    ) 2>&1 | tee logfile.log
    
     
  3. eva2000

    eva2000 Administrator Staff Member

    44,527
    10,170
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,742
    Local Time:
    3:15 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Both methods of I/O redirection work. I use a bit of both in Centmin Mod. The menu options use the 2nd you posted with piping to tee command.
     
  4. pamamolf

    pamamolf Premium Member Premium Member

    3,811
    369
    83
    May 31, 2014
    Ratings:
    +711
    Local Time:
    8:15 PM
    Nginx-1.17.x
    MariaDB 10.3.x
    If i want to test the first command:

    Code:
    exec "${@}" > >(tee logfile) 2>&1
    Where i must place it in the script?

    At the top after #/bin/bash or at the end of the script?
     
  5. eva2000

    eva2000 Administrator Staff Member

    44,527
    10,170
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,742
    Local Time:
    3:15 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x