Skip to content

Instantly share code, notes, and snippets.

@pnsinha
Created September 9, 2024 18:03
Show Gist options
  • Save pnsinha/7697664b15c22ea81b7102a126126957 to your computer and use it in GitHub Desktop.
Save pnsinha/7697664b15c22ea81b7102a126126957 to your computer and use it in GitHub Desktop.
#!/usr/bin/expect -f
# Set timeout for the script
set timeout 60
# Define variables for the second server
set my_server "midway3.rcc.uchicago.edu"
set my_username "pnsinha"
set my_password "your_password_here" ;
# Start the SSH session to the second server
spawn ssh $my_username@$my_server
# Handle the password prompt
expect {
"yes/no" {
send "yes\r"
expect "*?assword:*"
send "$my_password\r"
}
"*?assword:*" {
send "$my_password\r"
}
}
# Wait for 2 seconds after entering the password
sleep 2
# Handle the Duo two-factor authentication prompt
expect {
"Passcode or option (1-4):" {
send "2\r" ;# Automatically select option 2 for Duo Push
}
timeout {
puts "Duo prompt not received in time."
exit 1
}
}
# Interact with the server
expect "$ " ;
interact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment