#!/bin/bash ## This script to install qark SDK in batches ## @Author Rock apt-get install expect -y url="" file="qark.tar.gz" tmp_log="/tmp/qark_install.tmp" log_dir="logs" d=`date +%Y-%m-%d` log_file=$log_dir/install-$d.log if [ ! -d $log_dir ]; then mkdir $log_dir fi if [ ! $url ]; then echo "please input the url for download qark SDK." exit 1 fi if [ ! -f machine.txt ]; then echo "No machine.conf specified." exit 1 fi cat machine.conf | while read line do if [[ "$line" =~ ^#.* ]] || [ "$line" == "" ];then continue fi host=`echo "$line" | awk -F ' ' '{print $1}'` username=`echo "$line" | awk -F ' ' '{print $2}'` password=`echo "$line" | awk -F ' ' '{print $3}'` port=`echo "$line" | awk -F ' ' '{print $4}'` host_name=`echo "$line" | awk -F ' ' '{print $5}'` /usr/bin/expect < /etc/hostname\r" send "hostname $host_name\r" expect "root@*" send "wget '$url' -O $file\r" expect "root@*" send "tar -xzf $file\r" expect "root@*" send "bash uninstall.sh && rm -rf /etc/qark /var/run/qark\r" expect "root@*" send "bash install.sh\r" expect "#*" log_file $tmp_log send "rm -rf /tmp/qark && sleep 1 && ps aux|grep qark-executor\r" expect "#*" send "exit\r" send "exit\r" expect ef EOF # check if qark is installed succeed. num=$(cat $tmp_log | grep qark-executor | wc -l) # clear tmp_log cat /dev/null > $tmp_log now=`date '+%Y-%m-%d %H:%M:%S'` if (( $num >= 3 )); then echo "$now Install qark successfully, $username@$host:$port" >> $log_file else echo "$now Install qark failed, $username@$host:$port" >> $log_file fi done exit