脚本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.*}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。