首页 > 代码库 > 用shell编写批量打包日志脚本
用shell编写批量打包日志脚本
脚本1
#!/bin/bash DATE=$(date +%Y%m%d%H%M) NAME=$(echo $1 | awk -F‘,‘ ‘{print NF}‘) LOG_PATH="$2" if [ $# -ne 2 ];then echo "USAGE: sh $0 log_name1,log_name2 log_path" exit fi for NUM in `seq 1 $NAME` do LOG_NAME=$(echo $1 | cut -d ‘,‘ -f $NUM) for i in {1..6} do ansible -m synchronize -a "mode=pull src=http://www.mamicode.com/${LOG_PATH}${LOG_NAME} dest=/mnt/dx${i}${LOG_NAME}" dx${i}sock2 done for i in 1 2 3 4 do ansible -m synchronize -a "mode=pull src=http://www.mamicode.com/${LOG_PATH}${LOG_NAME} dest=/mnt/lt${i}${LOG_NAME}" lt${i}sock2 done for i in 179 yy 360 9377 do ansible -m synchronize -a "mode=pull src=http://www.mamicode.com/${LOG_PATH}${LOG_NAME} dest=/mnt/${i}${LOG_NAME}" ${i}sock2 done tar zcvf $DATE-${LOG_NAME}.tar.gz *${LOG_NAME} && rm -rf /mnt/*${LOG_NAME} done NUMBER=$(ls *.tar.gz | wc -l) if [ $NUMBER -gt 1 ];then TAR_NAME=$(echo ${LOG_NAME} | awk -F‘.‘ ‘{print $1}‘) tar zcvf ${DATE}-all-${TAR_NAME}.tar.gz *.tar.gz rm -rf /mnt/${DATE}-${TAR_NAME}*.tar.gz fi
脚本2
#!/bin/bash DATE=$(date +%Y%m%d%H%M) #NAME=$(echo $1 | awk -F‘,‘ ‘{print NF}‘) SHU="$1" NAME="$2" LOG_PATH="$3" if [ $# -ne 3 ];then echo "USAGE: sh $0 number log_name log_path" exit fi for NUM in `seq 1 $SHU` do for i in {1..6} do LOG_NAME=$(ansible -m shell -a "cd ${LOG_PATH};ls -l -t ${NAME}.* | awk ‘{print $9}‘ | head -${NUM} | tail -1" dx${i}sock2 | tail -1 | awk ‘{print $9}‘) ansible -m synchronize -a "mode=pull src=http://www.mamicode.com/${LOG_PATH}${LOG_NAME} dest=/mnt/dx${i}${LOG_NAME}" dx${i}sock2 done for i in 1 2 3 4 do LOG_NAME=$(ansible -m shell -a "cd ${LOG_PATH};ls -l -t ${NAME}.* | awk ‘{print $9}‘ | head -${NUM} | tail -1" lt${i}sock2 | tail -1 | awk ‘{print $9}‘) ansible -m synchronize -a "mode=pull src=http://www.mamicode.com/${LOG_PATH}${LOG_NAME} dest=/mnt/lt${i}${LOG_NAME}" lt${i}sock2 done for i in 179 yy 360 9377 do ansible -m synchronize -a "mode=pull src=http://www.mamicode.com/${LOG_PATH}${LOG_NAME} dest=/mnt/${i}${LOG_NAME}" ${i}sock2 done done tar zcvf $DATE-${NAME}-$NUM.tar.gz *${NAME}* && rm -rf /mnt/{*.log,*.log.*}
本文出自 “YHT的运维笔记” 博客,请务必保留此出处http://yht1990.blog.51cto.com/9014030/1926727
用shell编写批量打包日志脚本
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。