Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

254
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!