标签: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=${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=${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=${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=${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=${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=${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
原文地址:http://yht1990.blog.51cto.com/9014030/1926727