logfile="/tmp/online.log_$(date +%Y%m%d)"
#judge file is not hidden file or buffer file
[[ $watchfile =~ ^\. ]] && continue || echo "$watchfile is not buffer file or hidden file. next choice:''" &>> $logfile
#echo $date $event $watchdir $watchfile
#judge file endswith zip or war
endswith=$(echo $watchfile | awk -F"." '{printf ".%s\n",$NF}')
if [ "$endswith" != ".zip" -a "$endswith" != ".war" ];then
echo "$watchfile endswith isn't war or zip! " &>> $logfile
continue
else
echo "$watchfile endswith is zip or war. " &>> $logfile
fi
#[[ $watchfile =~ \.[war,zip]$ ]] || echo "$watchfile endswith isn't war or zip! " &>> $logfile
#[[ $watchfile =~ \.[war,zip]$ ]] && echo "$watchfile endswith is zip or war. " &>> $logfile || continue
#next
[ -e $tmpfile ] || touch $tmpfile
olditem=$(grep $watchfile $tmpfile | awk -F":" '$1~/^'"$watchfile"'$/{printf "%s:%s\n",$1,$2}')
md5=$(md5sum $var_dir/$watchfile | cut -d" " -f1)
newitem="${watchfile}:$md5"
for item in $(cat $tmpfile)
do
if [ -z $(echo $item | cut -d":" -f2) ];then
sed -i "/$item/d" $tmpfile
fi
done
if [ -z $olditem ];then
echo "${watchfile}:$RANDOM" >> $tmpfile
touch $var_dir/$watchfile
elif [ $(echo $olditem | cut -d":" -f2) == "$md5" ];then
echo "$watchfile is already online. Don't need online any more!" &>> /tmp/online.log_$(date +%Y%m%d)
else
sed -i "s/$olditem/$newitem/g" $tmpfile
echo "Start: $date --> $watchdir $event $watchfile" &>> /tmp/online.log_$(date +%Y%m%d)
plat_name="$(echo $watchfile | cut -d"." -f 1)"
port="$(echo $watchfile | cut -d"." -f 2)"
if [ -n "$port" -a "$port" != "zip" -a "$port" != "war" ];then
yml_name=${plat_name}.${port}
elif [ "$plat_name" == "xxx3" -a "$port" == "zip" ];then
yml_name=${plat_name}.${port}
else
yml_name=${plat_name}
fi
#echo "$yml_name $plat_name"
if echo ${platform[@]} | grep -w "$plat_name" &> /dev/null;then
if [ "$plat_name" == "${platform[3]}" ];then
execute $script_dir $yml_name $plat_name
goods_center_restart $script_dir $yml_name $plat_name
mail_x $plat_name
echo "End: $(date +%Y%m%d) --> $date $watchfile" &>> $logfile
else
execute $script_dir $yml_name $plat_name
mail_x $plat_name
echo "End: $date --> $watchfile" &>> $logfile
fi
else
echo "No $plat_name.yml!" &>> $logfile
fi
fi