Skip to content

Instantly share code, notes, and snippets.

@sanmai
Last active August 30, 2017 01:38
Show Gist options
  • Save sanmai/f8a78ae59b9ee3a7ead5e685ad848bae to your computer and use it in GitHub Desktop.
Save sanmai/f8a78ae59b9ee3a7ead5e685ad848bae to your computer and use it in GitHub Desktop.
$ add-date-suffix access.log.2.gz
'access.log.2.gz' -> 'access.log-20170821.gz'

Use this script if you happen to forget to add dateext for logrotate:

tee /etc/logrotate.d/defaults <<EOF
dateext
compress
delaycompress
EOF
#!/bin/sh
set -e
mv -nv "$1" $(echo $1 | sed -E "s/.[0-9]+/-$(date -r $1 +%F | sed s/-//g)/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment