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

    49,875
    11,487
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,839
    Local Time:
    1:24 PM
    Nginx 1.21.x
    MariaDB 10.x
  2. pamamolf

    pamamolf Well-Known Member

    4,003
    420
    83
    May 31, 2014
    Ratings:
    +812
    Local Time:
    6:24 AM
    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

    49,875
    11,487
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,839
    Local Time:
    1:24 PM
    Nginx 1.21.x
    MariaDB 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 Well-Known Member

    4,003
    420
    83
    May 31, 2014
    Ratings:
    +812
    Local Time:
    6:24 AM
    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

    49,875
    11,487
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,839
    Local Time:
    1:24 PM
    Nginx 1.21.x
    MariaDB 10.x