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 ...
随机推荐
- irc使用教程
下面介绍几个IRC名词:NICKNAME (或nick) 昵称.在命令中可以表示你本人或者其他聊天客.#CHANNEL (或#chan) 频道.聊天室房间名字.房间名字前面一定要加 # 符号.服务器机 ...
- ElasticSearch(六)底层索引控制
相似度算法 涉及到了ES的底层,首先讲一下ES的底层核心,相似度模型,ES的查询和传统的数据库查询最大的差别就在相似度查询(之前讲过,索引存储的最大差别就是讲非结构化数据转化为结构化),ES里面会给文 ...
- jenkins构建触发器详解-不登录触发远程构建
利用jenkins的远程构建功能,我们可以使用任何脚本,甚至定制一个Web页来控制Job的执行,但是远程构建你如果直接使用的话,老是需要登录才能执行,如何避免登录?稍微折腾了一下,调通了. 1.首先去 ...
- php 测试 程序执行时间,内存使用情况
memory_get_usage 可以分析内存占用空间. microtime 函数就可以分析程序执行时间. 上栗子: echo '开始内存:'.memory_get_usage(), ''; $tmp ...
- C++11--编译器生成的函数
using namespace std; class Dog {}; /* C++ 03 * 1 默认构造函数(只有当用户没有声明任何构造函数) * 2 拷贝构造(只有当用户没有声明5,6),扩展到C ...
- 【json】使用json和java对象的序列化和反序列化
TOC [[TOC]] 依赖 fastxml Jackson JSON Tutorial Do-JSON-with-Jackson.pdf-很详细 Creating Java List from JS ...
- 峰Redis学习(4)Redis 数据结构(List的操作)
第四节:Redis 数据结构之List 类型 存储list: ArrayList使用数组方式 LinkedList使用双向链接方式 双向链接表中增加数据 双向链接表中删除数据 存储list常用 ...
- Java学习——多线程例子:银行
package cys; public class Example9_3 { public static void main(String[] args) { // TODO Auto-generat ...
- [转][CentOS]开机时
来自:https://www.cnblogs.com/jcblog/p/6431252.html 在 CentOS 开机界面有两个菜单: 第一个选项正常启动,第二个选项急救模式启动(系统出项问题不能正 ...
- [UE4]蓝图比C++慢10倍,是吗?
首先,蓝图肯定是比C++慢. 任何脚本语言(需要解释执行的语言),和C++相比可能达到十倍甚至百倍的差距.比如Java.Python.Lua,JS. 脚本语言是运行在虚拟机上的,所以它们比起直接运行的 ...