#!/usr/bin/env bash # script to run query to databases function usage() { cat < /proc/sys/vm/drop_caches" if [[ "$restart_server_each_query" == "1" && "$use_service" == "1" ]]; then echo "restart server: $etc_init_d_service restart" sudo $etc_init_d_service restart fi for i in $(seq $TIMES) do if [[ -f $etc_init_d_service && "$use_service" == "1" ]]; then sudo $etc_init_d_service status server_status=$? expect -f $expect_file "" if [[ "$?" != "0" || $server_status != "0" ]]; then echo "restart server: $etc_init_d_service restart" sudo $etc_init_d_service restart fi #wait until can connect to server restart_timer=0 restart_limit=60 expect -f $expect_file "" &> /dev/null while [ "$?" != "0" ]; do echo "waiting" sleep 1 let "restart_timer = $restart_timer + 1" if (( $restart_limit < $restart_timer )); then sudo $etc_init_d_service restart restart_timer=0 fi expect -f $expect_file "" &> /dev/null done fi echo echo "times: $i" echo "query:" "$query" expect -f $expect_file "$query" done fi let "index = $index + 1" done } temp_test_file=temp_queries_$table_name cat $test_file | sed s/$table_name_pattern/$table_name/g > $temp_test_file mapfile -t test_queries < $temp_test_file echo "start time: $(date)" time execute "${test_queries[@]}" echo "stop time: $(date)"