Last active
June 24, 2020 22:48
-
-
Save ramonpin/6218637 to your computer and use it in GitHub Desktop.
Expect script to automatically create a ssh tunnel from a local port to a remote destination.
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 ssh_host "172.19.10.80" | |
set ssh_user "user" | |
set ssh_password "password" | |
set dest_host "172.19.10.91" | |
set dest_port 8080 | |
set local_port 80 | |
set timeout -1 | |
spawn ssh -N $ssh_user@$ssh_host -L 127.0.0.1:$local_port:$dest_host:$dest_port | |
expect -- "*?assword:*" | |
send $ssh_password | |
send "\r" | |
puts "\rTunnel stablished." | |
puts "\rEnter 'close' to finish tunneling." | |
expect_user -re "close" |
@ramonpin You do not need to duplicate 10-13, all you need to do is repeat -L 127.0.0.1:$local_port:$dest_host:$dest_port
on line 10 and it would set up multiple tunnels through a single session with no recursive sessions (which would happen with multiple 10-13 lines)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can be expanded to create several tunnels by duplicating lines 10-13 and adding the proper configuration variables.