Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a bash script where I configure my proxy settings automatically. I have created some aliases in the .bash_aliases file. Now there is one command where I ssh into my remote server and do some dynamic port forwarding and essentially create a socks proxy. So I need to configure my proxy settings accordingly.

The command looks like:

proxy off && ssh -D <port> <username>@<hostaddress>

I have aliased the above command and when I type the alias in the terminal, I am connected to my remote server successfully. However after this is done, I need to run another command in a new terminal window to configure my newly created socks proxy. Basically I just need to run:

proxy socks #It configures my laptop to use the socks proxy

I can't do it in the same terminal window and just && it after the ssh command because that would mean I am trying to execute the command on the remote server. I want to run this command on my laptop.

Is there any way I can run the second command in a new terminal window in a single line like we pipe or and different commands? It's really inefficient to open a new tab in the terminal every time I ssh into my remote server, just so that I can type a single command to configure my proxy and then close that tab because I don't need it anymore.

share|improve this question
    
Why not exit after the first command? –  i08in Feb 15 at 8:26
    
If i exit after the first command, would it not terminate the ssh session? –  Vivek Pradhan Feb 15 at 9:11
    
My bad, I misunderstood the question; ignore the comment, please. –  i08in Feb 15 at 9:14

1 Answer 1

up vote 1 down vote accepted

Try like this instead:

port=1234
remote=username@host
proxy off && ssh -fND $port $remote && proxy socks

The -f flag tells ssh to go into the background and the -N tells to not execute commands, just forward ports. This way you can continue working in your current terminal.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.