#!/bin/bash
yesterday=`date -d '-1 day' +%Y%m%d`
dat=`date "+%Y-%m-%d %H:%M:%S"`
url1="http://xxx:9096/page/downFile?date=${yesterday}&fileType=2"
url2="http://xxx:9096/page/downFile?date=$(date +%Y%m%d)&fileType=0"
REMOTE_HOST="pi1"
FileName1="/home/ansible/temp/${yesterday}_2.txt"
FileName2="/home/ansible/temp/${yesterday}_0.txt"
TempPath="/home/ansible/wz-temp/pahs_api/temp"
rsync_passwd="/home/ansible/wz-temp/pahs_api/conf/payhs_api.passwd"
Logfile="./logs/result.log"
ReplicatFromPi1(){
ansible pi1 -m shell -a "curl -X GET -o /home/ansible/temp/${yesterday}_2.txt 'http://10.26.208.129:9096/page/downFile?date=${yesterday}&fileType=2' "
if [[ $? -eq 0 ]]; then
printf "$dat get content from ${url1} succeed.\n" >> "${Logfile}"
else
printf "$dat get content from ${url1} failed.\n" >> "${Logfile}"
fi
scp "${REMOTE_HOST}":"${FileName1}" "${TempPath}"
if [[ $? -eq 0 ]]; then
printf "$dat copy ${yesterday}_2.txt from pi1 succeed.\n" >> "${Logfile}"
else
printf "$dat copy ${yesterday}_2.txt from pi1 failed.\n" >> "${Logfile}"
fi
ansible pi1 -m shell -a "curl -X GET -o /home/ansible/temp/${yesterday}_0.txt 'http://10.26.208.129:9096/page/downFile?date=${yesterday}&fileType=0' "
if [[ $? -eq 0 ]]; then
printf "$dat get content from ${url2} succeed.\n" >> "${Logfile}"
else
printf "$dat get content from ${url2} failed.\n" >> "${Logfile}"
fi
scp "${REMOTE_HOST}":"${FileName2}" "${TempPath}"
if [[ $? -eq 0 ]]; then
printf "$dat copy ${yesterday}_0.txt from pi1 succeed.\n" >> "${Logfile}"
else
printf "$dat copy ${yesterday}_0.txt from pi1 failed.\n" >> "${Logfile}"
fi
}
RsyncItranet(){
sudo /usr/bin/rsync -avz --port=19873 "${TempPath}"/"${yesterday}"_*.txt --password-file="${rsync_passwd}" --delete payhs_user@xxxx::PayhsFile
if [[ $? -eq 0 ]]; then
printf "$dat rsync to itranet host node30 succeed.\n" >> "${Logfile}"
else
printf "$dat rsync to itranet host node30 failed.\n" >> "${Logfile}"
fi
}
main(){
ReplicatFromPi1
RsyncItranet
}
main
同步线上文件到内网
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 解决方法 创建SSH Key 在用户目录下,看看有没有.ssh文件夹,如果有,再看看这个文件夹里有没有id_rsa...
- Today I went to a new summer camp site. Two of my friends...