Skip to content

Instantly share code, notes, and snippets.

@fire1ce
Last active November 4, 2023 06:40
Show Gist options
  • Save fire1ce/068cbf0802955fb2422fb7a64772b11a to your computer and use it in GitHub Desktop.
Save fire1ce/068cbf0802955fb2422fb7a64772b11a to your computer and use it in GitHub Desktop.

Revisions

  1. Stas Kosatuhin revised this gist Apr 8, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Bash stdout to file - Logger.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ Add the code below to .sh file.
    # exec 2<&- # Close STDERR FD

    parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
    LOG_FILE=$parent_path'/err.log' #log file name
    LOG_FILE=$parent_path'/error.log' #log file name
    exec 1>> $LOG_FILE # Open STDOUT as $LOG_FILE file for read and write.
    exec 2>&1 # Redirect STDERR to STDOUT
    echo | date "+%Y-%m-%d %H:%M:%S"
  2. Stas Kosatuhin revised this gist Apr 8, 2018. 1 changed file with 1 addition and 6 deletions.
    7 changes: 1 addition & 6 deletions Bash stdout to file - Logger.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,6 @@
    Dependencies: "moreutils" should be installed on the os

    use brew/apt-get/wget/yum install moreutils depends on you os.

    Add the code below to .sh file.



    ```bash
    # Optional:
    # exec 1<&- # Close STDOUT file descriptor
    @@ -15,7 +10,7 @@ parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
    LOG_FILE=$parent_path'/err.log' #log file name
    exec 1>> $LOG_FILE # Open STDOUT as $LOG_FILE file for read and write.
    exec 2>&1 # Redirect STDERR to STDOUT
    echo | ts '[%Y-%m-%d %H:%M:%S]'
    echo | date "+%Y-%m-%d %H:%M:%S"

    # example:
    echo "Time Stamp should be above this line"
  3. Stas Kosatuhin revised this gist Apr 8, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Bash stdout to file - Logger.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    Dependencies: "moreutils" should be installed on the os;
    Dependencies: "moreutils" should be installed on the os

    use brew/apt-get/wget/yum install moreutils depends on you os.

    Add the code below to .sh file.
  4. Stas Kosatuhin revised this gist Apr 8, 2018. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion Bash stdout to file - Logger.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,10 @@
    Dependencies: "moreutils" should be installed on the os.
    Dependencies: "moreutils" should be installed on the os;
    use brew/apt-get/wget/yum install moreutils depends on you os.

    Add the code below to .sh file.



    ```bash
    # Optional:
    # exec 1<&- # Close STDOUT file descriptor
  5. Stas Kosatuhin revised this gist Apr 8, 2018. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions Bash stdout to file - Logger.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,6 @@
    Dependencies: "moreutils" should be installed on the os

    use brew/apt-get/wget/yum install moreutils depends on you os

    Add the code below to .sh file
    Dependencies: "moreutils" should be installed on the os.
    use brew/apt-get/wget/yum install moreutils depends on you os.
    Add the code below to .sh file.


    ```bash
  6. Stas Kosatuhin revised this gist Apr 8, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Bash stdout to file - Logger.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    Dependencies: "moreutils" should be installed on the os

    use brew/apt-get/wget/yum install moreutils depends on you os

    Add the code below to .sh file
  7. Stas Kosatuhin revised this gist Apr 8, 2018. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion Bash stdout to file - Logger.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    Dependencies: "moreutils" should be installed on the os

    use brew/apt-get/wget/yum install moreutils depends on you os

    Add the code below to .sh file
  8. Stas Kosatuhin revised this gist Apr 8, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Bash stdout to file - Logger.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    Dependencies: "moreutils" should be installed on the os

    use brew/apt-get/wget/yum install moreutils depends on you os

    Add the code below to .sh file


  9. Stas Kosatuhin revised this gist Apr 8, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Bash stdout to file - Logger.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    Dependencies: "moreutils" should be installed on the os
    use brew/apt-get/wget/yum install moreutils depends on you os
    Add the code below to .sh file


    ```bash
    # Optional:
    # exec 1<&- # Close STDOUT file descriptor
  10. Stas Kosatuhin revised this gist Apr 8, 2018. No changes.
  11. Stas Kosatuhin revised this gist Apr 8, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Bash stdout to file - Logger.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ Add the code below to .sh file
    # exec 2<&- # Close STDERR FD

    parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
    LOG_FILE=$parent_path'/err.log' #Config file name to save
    LOG_FILE=$parent_path'/err.log' #log file name
    exec 1>> $LOG_FILE # Open STDOUT as $LOG_FILE file for read and write.
    exec 2>&1 # Redirect STDERR to STDOUT
    echo | ts '[%Y-%m-%d %H:%M:%S]'
  12. Stas Kosatuhin revised this gist Apr 8, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Bash stdout to file - Logger.md
    Original file line number Diff line number Diff line change
    @@ -11,8 +11,9 @@ exec 1>> $LOG_FILE # Open STDOUT as $LOG_FILE file for read and write.
    exec 2>&1 # Redirect STDERR to STDOUT
    echo | ts '[%Y-%m-%d %H:%M:%S]'

    # example:
    echo "Time Stamp should be above this line"
    echo nofile.example
    cat nofile.example
    ```


  13. Stas Kosatuhin revised this gist Apr 8, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Bash stdout to file - Logger.md
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,8 @@ exec 1>> $LOG_FILE # Open STDOUT as $LOG_FILE file for read and write.
    exec 2>&1 # Redirect STDERR to STDOUT
    echo | ts '[%Y-%m-%d %H:%M:%S]'

    echo "this sould be show in the err.log file"
    echo "Time Stamp should be above this line"
    echo nofile.example
    ```


  14. Stas Kosatuhin revised this gist Apr 8, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Bash stdout to file - Logger.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    add This to Bash code to ceate error log with time stemp
    Add the code below to .sh file

    ```bash
    # Optional:
    # exec 1<&- # Close STDOUT file descriptor
  15. Stas Kosatuhin renamed this gist Apr 8, 2018. 1 changed file with 0 additions and 0 deletions.
  16. Stas Kosatuhin revised this gist Apr 8, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Bash Error To File Logger.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    add This to Bash code to ceate error log with time stemp
    ```bash
    # Options:
    # Optional:
    # exec 1<&- # Close STDOUT file descriptor
    # exec 2<&- # Close STDERR FD

  17. Stas Kosatuhin renamed this gist Apr 8, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion error-to-file-logger.md → Bash Error To File Logger.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Ddd This to Bash code to ceate error log with time stemp
    add This to Bash code to ceate error log with time stemp
    ```bash
    # Options:
    # exec 1<&- # Close STDOUT file descriptor
  18. Stas Kosatuhin renamed this gist Apr 8, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  19. Stas Kosatuhin created this gist Apr 8, 2018.
    16 changes: 16 additions & 0 deletions error-to-file-logger.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    Ddd This to Bash code to ceate error log with time stemp
    ```bash
    # Options:
    # exec 1<&- # Close STDOUT file descriptor
    # exec 2<&- # Close STDERR FD
    parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
    LOG_FILE=$parent_path'/err.log' #Config file name to save
    exec 1>> $LOG_FILE # Open STDOUT as $LOG_FILE file for read and write.
    exec 2>&1 # Redirect STDERR to STDOUT
    echo | ts '[%Y-%m-%d %H:%M:%S]'
    echo "this sould be show in the err.log file"
    ```