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上传的更多相关文章

  1. shell脚本实现自动压缩一天前的日志文件 ,并传到ftp服务器上

    shell脚本实现自动压缩一天前的日志文件 ,并传到ftp服务器上 naonao_127关注2人评论19401人阅读2012-06-08 11:26:16         生产环境下脚本自动备份脚本是 ...

  2. WEB版一次选择多个文件进行批量上传(Plupload)的解决方案

    WEB版一次选择多个文件进行批量上传(Plupload)的解决方案  转载自http://www.cnblogs.com/chillsrc/archive/2013/01/30/2883648.htm ...

  3. 【应用】:shell crontab定时生成oracle表的数据到txt文件,并上传到ftp

    一.本人环境描述      1.oracle服务端装在win7 32位上,oracle版本为10.2.0.1.0      2.Linux为centos6.5 32位,安装在Oracle VM Vir ...

  4. WEB版一次选择多个文件进行批量上传(WebUploader)的解决方案

    本人在2010年时使用swfupload为核心进行文件的批量上传的解决方案.见文章:WEB版一次选择多个文件进行批量上传(swfupload)的解决方案. 本人在2013年时使用plupload为核心 ...

  5. WEB版一次选择多个文件进行批量上传(swfupload)的解决方案

    说明:功能完全支持ie和firefox浏览器! 一般的WEB方式文件上传只能使用FileUpload控件进行一个文件一个文件的进行上传,就算是批量上传,也要把文件一个一个的添加到页面,无法如windo ...

  6. [Plugin] WEB版一次选择多个文件进行批量上传(swfupload)的解决方案

    URL:http://www.cnblogs.com/chillsrc/archive/2010/02/21/1670594.html 说明:功能完全支持ie和firefox浏览器! 一般的WEB方式 ...

  7. ftp 根据特定正则匹配文件名 下载到本地 并且上传文件到ftp java *** 最爱那水货

    /** * 建立FTP链接,FTP服务器地址.端口.登陆用户信息都在配置里配置即可. * @throws IOException */ public boolean connectFtp(String ...

  8. 用OpenSSL命令行生成证书文件

    用OpenSSL命令行生成证书文件 1.首先要生成服务器端的私钥(key文件): openssl genrsa -des3 -out server.key 1024 运行时会提示输入密码,此密码用于加 ...

  9. shell脚本删除log日志

    删除log文件简单shell脚本 经常会遇到日志把磁盘占满的情况,引起低级故障.我个人在实际工作中,尝试了如下的方法,比较简单,而且快捷有效. #!/bin/bash # /root/log_dele ...

随机推荐

  1. [转]xargs详解

    为什么要用xargs,问题的来源 在工作中经常会接触到xargs命令,特别是在别人写的脚本里面也经常会遇到,但是却很容易与管道搞混淆,本篇会详细讲解到底什么是xargs命令,为什么要用xargs命令以 ...

  2. pri 知识点

    pri github:https://github.com/prijs/pri 添加路由后动态导入,使用的是 react-loadable:https://github.com/jamiebuilds ...

  3. roadhog 知识点

    roadhog 是一个 cli 工具,提供 server. build 和 test 三个命令,分别用于本地调试和构建,并且提供了特别易用的 mock 功能.命令行体验和 create-react-a ...

  4. npm install --save 和 --save-dev

    最近在写Node程序的时候,突然对 npm install 的-save和-save-dev 这两个参数的使用比较混乱.其实博主在这之前对这两个参数的理解也是模糊的,各种查资料和实践后对它们之间的异同 ...

  5. WCF入门教程(二)从零做起-创建WCF服务

    通过最基本的操作看到最简单的WCF如何实现的.这是VS的SDK默认创建的样本 1.创建WCF服务库 2.看其生成结构 1)IService1.cs(协议) 定义了协议,具体什么操作,操作的参数和返回值 ...

  6. 如何在linux服务器上使用hanlp

    关于如何在linux服务器上使用hanlp也有分享过一篇,但分享的内容与湘笑的这篇还是不同的.此处分享一下湘笑的这篇hanlp在linux服务器上使用的文章,供新手朋友学习之用. 本文主要工作是在li ...

  7. 【java_需阅读】Java中static关键字用法总结

    1.     静态方法 通常,在一个类中定义一个方法为static,那就是说,无需本类的对象即可调用此方法 声明为static的方法有以下几条限制: · 它们仅能调用其他的static 方法. · 它 ...

  8. system.Data.Entity.Infrastructure.DbUpdateConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0) 问题

    页面控件没有做限制.提交后还可以继续点击,造成了在短时间内的多次请求.查看日志两次错误在200ms之内. 错误信息 system.Data.Entity.Infrastructure.DbUpdate ...

  9. Java事件监听器的四种实现方式

    自身类作为事件监听器 外部类作为事件监听器 匿名内部类作为事件监听器 内部类作为事件监听器 自身类作为事件监听器: import javax.swing.*; import java.awt.*; i ...

  10. url参数 加密

    加密 url +? btoa(param) 解密 url + ?atob(param)