#!/bin/bash
read -s password
echo
read -s password_again
echo
trim() {
local var=1var="{var#"{var%%[![:space:]]*}"}"
var="{var%"{var##*[![:space:]]}"}"
echo -n "var"
}
password=(trim"password")
password_again=(trim"password_again")
if [ -z "password"]∣∣[−z"password_again" ] || [ "password"!="password_again" ]; then
exit 1
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
shopt -s expand_aliases
alias tailscale="/Applications/Tailscale.app/Contents/MacOS/Tailscale"
fi
log_file="/tmp/lm_qa/kikopi.log"
mkdir -p /tmp/lm_qa
touch logfileecho"">log_file
online_hosts=(tailscale status | grep -v "offline" | grep -E '^[0-9]' | grep -v "agent-dev" | grep -v "erdem" | grep -v "ywg" | awk '{print 1,2}')
online_hosts_array=(online_hosts)
total_hosts=(({#online_hosts_array[@]} / 2 ))
current_row=0
for i in "onlinehostsari =~ ^[0-9]+.[0-9]+.[0-9]+.[0-9]+i
else
current_row=(echo 1}')
fi
if [[ $hostname == "" ]]; then
continue
else
clear
echo "$current_row / $total_hosts"
echo "$ip $hostname"
echo "hostname: $hostname" >> $log_file
expect -c "
spawn ssh-copy-id -o ConnectTimeout=5 qa@$ip
expect {
\"yes/no\" { send \"yes\r\"; exp_continue }
\"assword:\" {
send \"$password\r\"
exp_continue
}
eof { exit }
}
interact
" >> "$log_file"
sleep 1
fi
done