Learn about Centmin Mod LEMP Stack today
Register Now

Create a bash script

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

Tags:
  1. eva2000

    eva2000 Administrator Staff Member

    54,564
    12,224
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,793
    Local Time:
    10:37 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  2. pamamolf

    pamamolf Premium Member Premium Member

    4,084
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    2:37 PM
    Nginx-1.25.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

    54,564
    12,224
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,793
    Local Time:
    10:37 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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

    4,084
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    2:37 PM
    Nginx-1.25.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

    54,564
    12,224
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,793
    Local Time:
    10:37 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+