Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

249
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda