shell脚本选择LOG里面特定的行,生成新文件并rsync上传
2017-11-24 14:23
471 查看
rsync.sh
killrsync.sh
配置文件conf.properties
start.sh
创建软连接
#!/bin/bash tool_path=$(cd `dirname $0`; 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=0;i<3;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 873 --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 $0`; 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 -9
配置文件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 $0`; 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 $1` do if [ x"$file2" != x"." -a x"$file2" != x".." ]; then if [ -d "$1/$file2" ];then echo "$1/$file2" cd $1/${file2} folder_name=${1//${log_root}/} cat $1/${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 $0) 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
相关文章推荐
- CentOS中使用Shell脚本实现每天自动备份网站文件和数据库并上传到FTP中
- 【shell脚本】匹配文件中特定的段落
- shell脚本编程实现计算器功能并根据选择将其保存于文件中
- 用shell脚本生成日志文件
- shell统计文件里面特定字符串出现次数
- Linux下shell脚本模拟自动上传文件
- Shell脚本实现上传zip压缩文件到FTP服务器
- shell脚本(从一些文件中查找含有特定字符的文件,将转移到指定地方)
- 日志定时压缩清理shell脚本(日志文件后缀格式如xxxxx.log.2017-07-10)
- shell脚本解压文件与选择选项
- shell脚本进行sftp文件批量上传与下载
- shell脚本显示选定路径下大于特定值文件
- shell脚本批量生成配置文件
- CentOS中使用Shell脚本实现每天自动备份网站文件和数据库并上传到FTP中
- 通过SHELL脚本实现SFTP文件自动上传与下载
- shell小脚本实现上传目录中的所有文件到服务器
- Shell脚本:使用rsync备份文件/目录
- 如何使用Shell脚本编译生成Archive文件并导出签名IPA文件。
- ftp自动上传下载文件(Shell脚本)及ftp命令详解
- 批量上传文件到HDFS的Shell脚本