shell脚本选择LOG里面特定的行,生成新文件并rsync上传
rsync.sh
#!/bin/bash tool_path=$(cd `dirname $`; pwd)
eval `cat ${tool_path}/conf.properties` rsync_include=${tool_path}/include/rsync_include.lst export RSYNC_PASSWORD=密码 echo `date '+%Y-%m-%d %T'` >> ${tool_path}/rsync.log
for((i=;i<;i++));
do
dstDate=`date -d "-$i day" +"%Y%m%d"`
localPath=${tool_path}"/tlog/"$dstDate"/"
echo $localPath
if [[ -d "$localPath" ]] ; then
startTime=`date -d "-$i day" +"%s"`
echo "start rsync file for $localPath ---------------------" >> ${tool_path}/rsync.log
rsync -rvzPL --append --port --include-from=${rsync_include} ${localPath} gameserverlog@rsync2.com::game_server_log_rsync/${game_id}/$dstDate
endTime=`date -d "-$i day" +"%s"`
echo "finish rsync file for $localPath, used time: $[((endTime - startTime))] seconds --------------------" >> ${tool_path}/rsync.log
fi
done
killrsync.sh
#!/bin/bash
tool_path=$(cd `dirname $`; pwd)
eval `cat ${tool_path}/conf.properties` source ~/.bash_profile
SYSTEM_TIME=`date '+%Y-%m-%d %T'` pid=`ps -e -o 'pid,args' |grep ${tool_path}/include|awk '{print $1}'`
echo "$SYSTEM_TIME kill rsync $pid" >> ${tool_path}/rsync.log ps -e -o 'pid,args' |grep ${tool_path}/include|grep -v grep|awk '{print $1}'|xargs kill -
配置文件conf.properties
log_root=/data/log
file_name_prefix=aa
file_name_suffix=.log
game_id=games2
start.sh
#!/bin/bash
source /etc/profile tool_path=$(cd `dirname $`; pwd)
eval `cat ${tool_path}/conf.properties`
echo ${tool_path}
echo ${log_root} ###
#yyyy-mm-dd
date_today=`date +"%Y-%m-%d"`
date_yesterday=`date -d "yesterday" +%Y-%m-%d` #yyyymmdd
date_today_hadoop=`date +"%Y%m%d"`
date_yesterday_hadoop=`date -d "yesterday" +%Y%m%d` #yyyymd
file_today=${date_today//-0/-}
file_yesterday=${date_yesterday//-0/-} ### kill rsync
${tool_path}/killrsync.sh ###
destFile_yesterday="${tool_path}/tlog/${date_yesterday_hadoop}"
if [[ ! -d ${destFile_yesterday} ]]; then
mkdir -p ${destFile_yesterday}
fi destFile_today="${tool_path}/tlog/${date_today_hadoop}"
if [[ ! -d ${destFile_today} ]]; then
mkdir -p ${destFile_today}
fi ###
cd ${log_root}
list_alldir(){
for file2 in `ls -a $`
do
if [ x"$file2" != x"." -a x"$file2" != x".." ]; then
if [ -d "$1/$file2" ];then
echo "$1/$file2"
cd $/${file2}
folder_name=${//${log_root}/}
cat $/${file2}/*.${file_yesterday} | grep '20..-.*LOG:.*|.*|.*|.*' | awk '{$1="";$2="";$3="";$4="";sub(" LOG:", "");print}' > ${destFile_yesterday}/tlog_${date_yesterday_hadoop}_${folder_name//\//_}_${file2}.log
cat $1/${file2}/*.${file_today} | grep '20..-.*LOG:.*|.*|.*|.*' | awk '{$1="";$2="";$3="";$4="";sub(" LOG:", "");print}' > ${destFile_today}/tlog_${date_today_hadoop}_${folder_name//\//_}_${file2}.log list_alldir "$1/${file2}"
fi
fi
done
} list_alldir ${log_root} cd ${destFile_yesterday}
find . -name "*" -type f -size 0c | xargs -n 1 rm -f
cd ${destFile_today}
find . -name "*" -type f -size 0c | xargs -n 1 rm -f ### start rsync
flock -xn ${tool_path}/rsync.lock -c "${tool_path}/rsync.sh"
创建软连接
#!/bin/bash
source /etc/profile
cd $(dirname $)
tool_path=`pwd`
eval `cat ${tool_path}/conf.properties`
root="$log_root"
for file in $root/*;
do
fileName=${file##*/}
datestr=`echo ${fileName} |cut -d '_' -f2`
destFile="${tool_path}/tlog/${datestr}"
if [[ ! -d ${destFile} ]]; then
mkdir -p ${destFile}
fi if [[ ! -L "${destFile}/${fileName}" ]]; then
ln -s ${file} ${destFile}
fi
done
shell脚本选择LOG里面特定的行,生成新文件并rsync上传的更多相关文章
- shell脚本实现自动压缩一天前的日志文件 ,并传到ftp服务器上
shell脚本实现自动压缩一天前的日志文件 ,并传到ftp服务器上 naonao_127关注2人评论19401人阅读2012-06-08 11:26:16 生产环境下脚本自动备份脚本是 ...
- WEB版一次选择多个文件进行批量上传(Plupload)的解决方案
WEB版一次选择多个文件进行批量上传(Plupload)的解决方案 转载自http://www.cnblogs.com/chillsrc/archive/2013/01/30/2883648.htm ...
- 【应用】:shell crontab定时生成oracle表的数据到txt文件,并上传到ftp
一.本人环境描述 1.oracle服务端装在win7 32位上,oracle版本为10.2.0.1.0 2.Linux为centos6.5 32位,安装在Oracle VM Vir ...
- WEB版一次选择多个文件进行批量上传(WebUploader)的解决方案
本人在2010年时使用swfupload为核心进行文件的批量上传的解决方案.见文章:WEB版一次选择多个文件进行批量上传(swfupload)的解决方案. 本人在2013年时使用plupload为核心 ...
- WEB版一次选择多个文件进行批量上传(swfupload)的解决方案
说明:功能完全支持ie和firefox浏览器! 一般的WEB方式文件上传只能使用FileUpload控件进行一个文件一个文件的进行上传,就算是批量上传,也要把文件一个一个的添加到页面,无法如windo ...
- [Plugin] WEB版一次选择多个文件进行批量上传(swfupload)的解决方案
URL:http://www.cnblogs.com/chillsrc/archive/2010/02/21/1670594.html 说明:功能完全支持ie和firefox浏览器! 一般的WEB方式 ...
- ftp 根据特定正则匹配文件名 下载到本地 并且上传文件到ftp java *** 最爱那水货
/** * 建立FTP链接,FTP服务器地址.端口.登陆用户信息都在配置里配置即可. * @throws IOException */ public boolean connectFtp(String ...
- 用OpenSSL命令行生成证书文件
用OpenSSL命令行生成证书文件 1.首先要生成服务器端的私钥(key文件): openssl genrsa -des3 -out server.key 1024 运行时会提示输入密码,此密码用于加 ...
- shell脚本删除log日志
删除log文件简单shell脚本 经常会遇到日志把磁盘占满的情况,引起低级故障.我个人在实际工作中,尝试了如下的方法,比较简单,而且快捷有效. #!/bin/bash # /root/log_dele ...
随机推荐
- parcel (另一个打包工具)知识点
ParcelJS 本身是 0 配置的,但 HTML.JS 和 CSS 分别是通过 posthtml.babel 和 postcss 处理的,所以我们得分别配 .posthtmlrc..babelrc ...
- c++获取键盘输入cin、scanf使用详解
cin是c++标准,scanf是在c中使用的 #include<cstdio> #include<iostream> #include<cstring> using ...
- Zookeeper 基本概念学习
1.Zookeeper简介: 1) 中间件,为分布式系统提供协调服务 2) 作用于分布式系统,发挥其优势,可以为大数据服务 3) 支持Java,提供java和c语言的客户端api 2. 分布式系统 1 ...
- EntityFrameworkCore操作记录
Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design -Version 2.0.3 Add-Migration Init U ...
- Spring Boot 监控与管理
在微服务架构中,我们将原本庞大的单体系统拆分为多个提供不同服务的应用,虽然,各个应用的内部逻辑因分解而简化,但由于部署的应用数量成倍增长,使得系统的维护复杂度大大提升,为了让运维系统能够获取各个为服务 ...
- mybatis源码阅读心得
第一天阅读源码及创建时序图.(第一次用prosson画时序图,挺丑..) 1. 调用 SqlSessionFactoryBuilder 对象的 build(inputStream) 方法: 2. ...
- 基于redis的乐观锁实践
redis真是一个分布式应用场景下的好东西,对于我们的应用设计,功劳大大的! 今天要研究的是基于redis的事务机制以及watch指令(CAS)实现乐观锁的过程. 所谓乐观锁,就是利用版本号比较机制, ...
- mysql 性能
https://blog.csdn.net/zengxuewen2045/article/category/6388631 #sda 磁盘信息dstat -D sda 3 5 #找出系统瓶颈dstat ...
- What is LBHttpSolrServer?
LBHttpSolrServer or "Load Balanced HttpSolrServer" is just a wrapper to CommonsHttpSolrSer ...
- 微服务测试打桩/mock工具mountebank
1,安装 Linux安装包,不用安装Node.js https://s3.amazonaws.com/mountebank/v1.10/mountebank-v1.10.0-linux-x64.tar ...