Discover Centmin Mod today
Register Now

Create a bash script

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

Tags:
  1. eva2000

    eva2000 Administrator Staff Member

    58,893
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    10:20 AM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
  2. pamamolf

    pamamolf Well-Known Member

    4,125
    429
    83
    May 31, 2014
    Ratings:
    +841
    Local Time:
    3:20 AM
    Nginx-1.29.x
    MariaDB 10.6.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

    58,893
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    10:20 AM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    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,125
    429
    83
    May 31, 2014
    Ratings:
    +841
    Local Time:
    3:20 AM
    Nginx-1.29.x
    MariaDB 10.6.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

    58,893
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    10:20 AM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+