Skip to content

Instantly share code, notes, and snippets.

@bageljp
Created February 10, 2014 08:31
Show Gist options
  • Select an option

  • Save bageljp/8912302 to your computer and use it in GitHub Desktop.

Select an option

Save bageljp/8912302 to your computer and use it in GitHub Desktop.
tomcat log delete script.
#!/bin/bash
#
# crontab -l
# 00 3 * * * /usr/local/tlab/script/tomcat_log_del.bash tomcat_front > /dev/null 2>&1
#
#----------
# define.
#----------
TOMCAT_UNIQ="${1:-tomcat}"
DIR_TOMCAT="/usr/local/${TOMCAT_UNIQ}"
DIR_LOG="${DIR_TOMCAT}/logs"
DIR_TMP="/usr/local/tlab/tmp"
LOG_TMP="${DIR_TMP}/`basename $0 .bash`_${TOMCAT_UNIQ}.log"
DEL_DAYS="31"
CMD_FIND="/usr/bin/find"
CMD_XARGS="/usr/bin/xargs"
#----------
# main.
#----------
if [ ! -d ${DIR_TMP} ]; then
mkdir -p ${DIR_TMP}
fi
cd ${DIR_LOG} || exit 1
${CMD_FIND} "${DIR_LOG:-/notdefine}" -name "*.[log|out]*" -type f -mtime +${DEL_DAYS} -print0 | ${CMD_XARGS} -0 ls -l > ${LOG_TMP}
${CMD_FIND} "${DIR_LOG:-/notdefine}" -name "*.[log|out]*" -type f -mtime +${DEL_DAYS} -print0 | ${CMD_XARGS} -0 rm -f
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment