Created
November 28, 2018 06:21
-
-
Save shiumachi/a49275347d6484e397961108a7f1e859 to your computer and use it in GitHub Desktop.
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/bash | |
usage() | |
{ | |
echo "usage: zip_logs.sh [directory] [-prod]" >&2 | |
exit 0 | |
} | |
TEMP=`getopt :h $*` | |
if [ $? != 0 ] ; then | |
usage | |
fi | |
eval set -- "$TEMP" | |
while true ; do | |
case "$1" in | |
-h|--help) | |
usage | |
shift ;; | |
--) shift ; break ;; | |
*) break ;; | |
esac | |
done | |
if [ $# -ge 1 -a "$1" != "-prod" ]; then | |
TARGET_DIR=$1 | |
shift | |
else | |
TARGET_DIR=./ | |
fi | |
echo "*** target file list ***" | |
find -E ${TARGET_DIR} -regex ".*\.(log|out)(.*[^zns]|.?)" -type f | |
if [ $# -ge 1 -a "$1" == "-prod" ]; then | |
echo "*** gzip compression start ***" | |
find -E ${TARGET_DIR} -regex ".*(log|out)(.*[^zns]|.?)" -type f -exec gzip "{}" \; | |
echo "*** compression done ***" | |
else | |
echo "*** dry run finished. please add '-prod' to execute ***" | |
usage | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment