back_day=`date -d '1 day ago' +%Y-%m-%d`
finance_linux_log_user=/home/admin/output/logs/user
TARGET_SERVER="crmfinance1 crmfinance2 crm-finance03"
TARGET_GOV_AUTO_DRAFT=${finance_linux_log_user}/govAutoDraft.log.${back_day}
TARGET_GOV_AUTO_DRAFT_LOG_FOLDER=${finance_linux_log_user}/back_govAutoDraft
TARGET_GOV_AUTO_DRAFT_LOG_TMP=${TARGET_GOV_AUTO_DRAFT_LOG_FOLDER}/govAutoDraft.log.tmp
TARGET_GOV_AUTO_EXCEPTION=${TARGET_GOV_AUTO_DRAFT_LOG_FOLDER}/govAutoDraftExceptiom
if [ ! -d "${TARGET_GOV_AUTO_DRAFT_LOG_FOLDER}" ];then
mkdir ${TARGET_GOV_AUTO_DRAFT_LOG_FOLDER}
fi
for A_MACHINE in ${TARGET_SERVER}
do
ssh ${A_MACHINE} test -f ${TARGET_GOV_AUTO_DRAFT}
if [ $? -eq 0 ];then
scp admin@$A_MACHINE:${TARGET_GOV_AUTO_DRAFT} ${TARGET_GOV_AUTO_DRAFT_LOG_TMP} >/dev/null
if [ `cat ${TARGET_GOV_AUTO_DRAFT_LOG_TMP} | grep 'Excepiton' | wc -l` -gt 0 ];then
echo $A_MACHINE >> ${TARGET_GOV_AUTO_EXCEPTION}
cat ${TARGET_GOV_AUTO_DRAFT_LOG_TMP} | grep 'Excepiton' >>${TARGET_GOV_AUTO_EXCEPTION}
rm -rf ${TARGET_GOV_AUTO_DRAFT_LOG_TMP}
fi
fi
done
if [ -f "${TARGET_GOV_AUTO_EXCEPTION}" ]; then
smtpclient -S 172.16.126.67 -P 25 -f result@member.alibaba.com -s 'there are exception in govAutoDraft operatio' dragon.caol@alibaba-inc.com di.caod@alibaba-inc.com <${TARGET_GOV_AUTO_EXCEPTION}
mv ${TARGET_GOV_AUTO_EXCEPTION} ${TARGET_GOV_AUTO_EXCEPTION}.${back_day}
rm -rf ${TARGET_GOV_AUTO_EXCEPTION}
fi