Answer the question
In order to leave comments, you need to log in
Automate ssh connection with expect?
There is a bash script that, under certain conditions, must connect via ssh to different hosts and take files from them. To automate this process, a function was created in the script to connect with expect.
SSH1() {
#Список хостов:
HOSTS=$(cat /home/ip.txt | grep "client-$num" | awk '{print $2}')
#Команды для expect:
COMM="
#Соедиение ssh:
spawn scp -r [email protected]$HOSTS:/home/client/ /etc/openvpn/keys/
expect \"*(yes/no)?*\" {send \"yes\r\"}
expect \"Password:\"
send \"$PASSWD\r\"
#Завершение выполнения expect:
expect eof
"
#Запуск expect с набором команд:
expect -c "$COMM"
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question