D
D
Dana2018-07-10 15:41:03
bash
Dana, 2018-07-10 15:41:03

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"
}

After the files have been taken from the host, you need to check these files and run a couple more commands.
But all commands that are after this function are displayed in the console with a "+" at the beginning and are not executed. I understand that expect perceives them as its own commands. How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2018-07-11
@saboteur_kiev

Why do you need an exp?
Authorization in ssh with passwords is the last century.
Set up SSH keys and just scp without passwords.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question