set timeout 240
xlsx2csv test.xlsx > temp.csv
declare -A data
row=1
while IFS=, read -r col1 col2 col3 col4 col5; do
data[$row,1]=$col1
data[$row,2]=$col2
data[$row,3]=$col3
data[$row,4]=$col4
data[$row,5]=$col5
((row++))
done < temp.csv
echo $row
index=2
echo $index
num=$row-1
echo $num
while(($index<=$num))
do
echo ${data[$index,4]}
let "index++"
spawn ./ProjectCreator.out
expect {
"Please input IP of the database(请输入数据库IP):" { send "${data[$index,1]}\r"; exp_continue}
"Please input port of the database(请输入数据库端口):" { send "${data[$index,2]}\r"; exp_continue }
"Please input username of the database(请输入数据库用户名):" { send "${data[$index,3]}\r"; exp_continue}
"Please input the password of the database(请输入数据库密码):" { send "${data[$index,4]}\r"; exp_continue}
"Please input the project name(请输入项目名称):" { send "${data[$index,5]}\r"; exp_continue}}
interact
sleep 180
psql "host=192.168.0.100 port=5432 user=postgres password=postgres dbname=postgres" <<-EOF
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE datname="PECSTAR_CONFIG_${data[$index,5]}" AND pid<>pg_backend_pid();
drop database "PECSTAR_CONFIG_${data[$index,5]}";
EOF
done
rm temp.csv