Created
April 4, 2020 12:52
-
-
Save caramelchocolate/f4e51f89b8cd9cef2d8627c44f4087a0 to your computer and use it in GitHub Desktop.
Write log to file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
dir_path="/path/" | |
date_str=$(date "+%Y%m%d_%H%M%S") | |
log_name="${dir_path}/${date_str}.log" | |
touch "${log_name}" | |
command 2>&1 | tee -a ${log_name}; | |
# or | |
command >> "${log_name}" 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment