tx2_update_full_speed.sh 1.64 KB
#!/bin/bash
ori_dir=$(cd $(dirname $0);pwd)
cd $ori_dir
if [[ -p fifo_tmp ]]
then
    rm fifo_tmp
fi
list_name=$1
file=$2
thread_num=11
mkfifo fifo_tmp
exec 9<>fifo_tmp

for i in `seq 1 $thread_num`
do
    echo -ne "\n">&9
done

echo -e "\033[41;33mClean up residual of ansible tools, syslog and VAServer!\033[0m"
ansible $list_name -b -m raw -a "if [ -d /home/ubuntu/.ansible/tmp ];then rm -r /home/ubuntu/.ansible/tmp;fi;if [ -d /root/.ansible/tmp ];then rm -r /root/.ansible/tmp;fi;size=\$(du -sm /var/log|awk '{print \$1}');if [ \$size -gt 1000 ];then echo clean syslog;cat /dev/null > /var/log/syslog;cat /dev/null > /var/log/syslog.1;fi;cd /root/UserApp/services/analysis_service;if [ -d VAServer ];then rm -r VAServer;fi;pkill -9 VAServer;cat /dev/null"

echo -e "\033[41;33mCopy the analyzer to the child node!\033[0m"
hosts=`ansible $list_name --list-hosts|egrep -o [0-9]+.[0-9]+.[0-9]+.[0-9]+`
if [[ ! $hosts ]]
then
    echo Please check /etc/ansible/hosts!
    exit 0
fi

chmod 666 $file
time1=`date +%s`

IFS=$' '
while read host
do
    read -u 9
    {
        sshpass -p ubuntu scp -o StrictHostKeyChecking=no $file ubuntu@$host:/home/ubuntu
        printf "%-20s : %-8s\n-----------------\n\n" "==> $host" "DONE!"
        echo -ne "\n">&9
    } &
done <<< $hosts
wait
time2=`date +%s`

let cov=$time2-$time1
exec 9<&-;exec 9>&-
rm fifo_tmp

time2=`date +%s`
let use=time2-time1
echo Time-consuming: $use's'

echo -e "\033[41;33mUnzip the analyzer and clean the cache!\033[0m" 
ansible $list_name -b -m raw -a "cd /home/ubuntu/;tar -zxf $file -C  /root/UserApp/services/analysis_service/;rm $file;cat /root/UserApp/services/analysis_service/VAServer/last_version"