Skip to content

Instantly share code, notes, and snippets.

@shiumachi
Created November 28, 2018 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiumachi/a49275347d6484e397961108a7f1e859 to your computer and use it in GitHub Desktop.
Save shiumachi/a49275347d6484e397961108a7f1e859 to your computer and use it in GitHub Desktop.
#!/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