1

I'm a CS student, and still learning a lot of these things, and so please bear with me if I don't have a full grasp on what I'm trying here.

I'm on a Mac, connecting to a linux machine. I can set up an ssh tunnel and connect to the remote machine by executing the following line of script:

ssh -f -L 2222:<remote_machine>:22 <user>@<remote_server> sleep 10; ssh -p 2222 <user>@localhost 

What I want to do is somehow execute this line automatically. Now, I have to copy and paste it into the terminal. I have key pairs set up, so don't have to enter passwords, but I get the prompt for my terminal type. These are the two steps I'd like to eliminate, so I can open terminal and run a script that eliminates these two steps.

What I can't figure out is how to either respond to the "terminal type" prompt or automatically respond to it. I've played around with the Expect class, and Python's pexpect module, but not had success (it seems like an expect script would be able to take care of the terminal portion, but having trouble creating the tunnel and not losing reference to the background process).

I have an applescript that does what I want, but would like a more portable solution. Any suggestions about where to look would be great!

0

2 Answers 2

0

You can put this command in a normal text file, which starts with

#!/bin/bash
ssh -f -L 2222:<remote_machine>:22 <user>@<remote_server> sleep 10; ssh -p 2222 <user>@localhost 

Then mark it as executable and it should start with a double-click

See here for more infos on shell scripts with OS-X

http://www.noendpress.com/vroman/shellscripting/

5
  • 1
    Thanks - I want to be able to automate the response when prompted for terminal type though - that's the main problem I have. I don't know how I can do that with a bash script, which is why I was looking for other options.
    – Rebecca
    Commented Apr 19, 2013 at 23:28
  • See the last comment here to add to this script in order to do an automated response: unix.com/shell-programming-scripting/…
    – MaQleod
    Commented Apr 19, 2013 at 23:51
  • I looked thru the comments there, but don't understand how that would apply here. Can you explain a little more? It seems like in that example, the goal is getting user input.
    – Rebecca
    Commented Apr 20, 2013 at 21:44
  • What is the terminal type you have on the OS-X side ? Normaly this type is taken and "forwarded" to the server side of ssh. Depending on your ssh client on OS-X, perhaps this one applies ? rit.edu/its/services/desktop_support/mac/… Commented Apr 22, 2013 at 8:47
  • It runs the specified command and then when there is a prompt for user input it inputs what you specify. Imagine that the example script is the like the script in this answer where it does an ssh command. You'd create another script that looks like the second option. When the second script runs and calls the first script, it'll answer the prompt with whatever is between the EOF entries.
    – MaQleod
    Commented Apr 22, 2013 at 22:39
0

The easiest way eould be to create ana alias for this command. Add this line to your $HOMe/.bashrc file:

alias tunnel='ssh -f -L 2222:<remote_machine>:22 <user>@<remote_server> sleep 10; ssh -p 2222 user@localhost'

Then from a normal terminal, you will be able to launch your tunnel by running

tunnel
1
  • Thanks - I want to be able to automate the response when prompted for terminal type though - that's the main problem I have. I don't know how I can do that with a bash script, which is why I was looking for other options.
    – Rebecca
    Commented Apr 19, 2013 at 23:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .