例子,服务器日志批量切割工具shell实例代码。
复制代码 代码示例:
#!/bin/bash
# www.jb200.com
#
logsPath=/web/logs/
workPath=$1
if [ -z ${workPath} ];then
echo "参数异常"
exit
fi
if [ ! -d logsPath ];then
mkdir -p ${logsPath}
fi
# supported paths
for appPath in ${workPath}*; do
${appPath}/bin/shutdown.sh
sleep 10
cat ${appPath}/logs/catalina.out > ${appPath}/logs/catalina.out.`date +%Y%m%d`
cat /dev/null > ${appPath}/logs/catalina.out
echo "daily rotating for "${appPath}" successfully at "`date +%Y%m%d` >> ${logsPath}/catalina_log.txt
${appPath}/bin/startup.sh
done
以上就是用shell脚本批量切割日志文件的方法,希望对大家有所帮助。