Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

250
Visualizações
Expect script to handle RSA finger print keys

I am trying to make my expect script more robust and to be able to handle more situations to be more automated. Currently my script works fine, however, there are times where I will be asked to add the RSA keys to known_hosts, I want this to default to yes all the time. My server doesn't always ask for the keys, once added then after awhile it wont ask until you delete the keys or switch gatways. After looking online i have tried to add this (commented code) in my working code and after added that it stalls at password input screen if RSA key had been added already.

So my question is, is there a way to handle this situation lets say if RSA has been added already, it will just skip to the password line?

[user@gateway my_direcotry]$ cat loadItTest
#!/usr/bin/expect -f

set timeout 600
set user root
set host 1.1.1.1
set pass pass


spawn ssh $user@$host

#expect {
#    -re "RSA key fingerprint" {send "yes\r"}
#}

expect "assword:"
send "$pass\r"
expect "#"

Sample output:

[root@gateway my_direcotry]# loadItTest
spawn ssh root@1.1.1.1
root@1.1.1.1's password:
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This is where the exp_continue command comes into play, to essentially create a "loop" within the expect command:

spawn ssh $user@$host
expect {
    "RSA key fingerprint" {send "yes\r"; exp_continue}
    "assword:" {send "$pass\r"}
}
expect "#"

If you see the "RSA key" pattern, answer "yes" but then keep waiting for the "assword" pattern. If you don't see "assword" before "RSA key", that's OK.

The body for the "assword" pattern does not contain exp_continue. After you send the password, the enclosing expect command will return, and the next command is to expect your prompt.

Note I removed the -re option: there are no regex-special characters in that pattern.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda