Created
September 9, 2024 18:03
-
-
Save pnsinha/7697664b15c22ea81b7102a126126957 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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