Skip to content

Instantly share code, notes, and snippets.

@kasymovga
Last active October 27, 2020 13:20
Show Gist options
  • Save kasymovga/7b907dc92654dbc22b3d8d2c344ccf47 to your computer and use it in GitHub Desktop.
Save kasymovga/7b907dc92654dbc22b3d8d2c344ccf47 to your computer and use it in GitHub Desktop.

Hacks to split stdout to log files.

With tee:

| LOGPREFIX="/path/to/log/locations/log-" LOGSUFFIX=".log" split -l 10000 --filter 'rm -f `ls -t "$LOGPREFIX"*"$LOGSUFFIX"|tail -n +3`; exec tee -a "$LOGPREFIX`date +%Y%m%d%H`$LOGSUFFIX"' - none

Without tee:

| LOGPREFIX="/path/to/log/locations/log-" LOGSUFFIX=".log" split -l 10000 --filter 'rm -f `ls -t "$LOGPREFIX"*"$LOGSUFFIX"|tail -n +3`; exec cat >> "$LOGPREFIX`date +%Y%m%d%H`$LOGSUFFIX"' - none

Note, not working in CentOS 7 because of buggy version of split.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment