Running a command in a new terminal instance in a bash script

Vivek Pradhan

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.

janos

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.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Running the script to invoke command in terminal

分類Dev

Command works in terminal but not in bash script

分類Dev

Running a shell script with and without "bash" command

分類Dev

~/.profile, ~/.bashrc, and ~/.bash_profile not running on new terminal start up

分類Dev

Script running from terminal but not in crontab

分類Dev

New Terminal bash file error

分類Dev

Commands Working In Terminal, But Not In Bash Script

分類Dev

Shortcut for running terminal command in VS code

分類Dev

Running a program from terminal, "command not found"

分類Dev

Printing the result of the script(running in background) on the terminal

分類Dev

Running script and defining object value in terminal window

分類Dev

Running bash script in a kubernetes pod

分類Dev

bash_completion causing a 'command not found' in terminal

分類Dev

echo/printf incomplete command at bash terminal

分類Dev

-bash: 400:: command not found when open terminal

分類Dev

Execute sed command in a bash script

分類Dev

Bash script - unix - command not found

分類Dev

exit a bash command in a script without exiting the script

分類Dev

Using bash variables in perl command in bash script

分類Dev

Shell script wrapper to prevent running command with no arguments?

分類Dev

Running PHP works in Command Prompt but not Git Bash

分類Dev

real-time search in terminal output stream; after running a command

分類Dev

How to make the top bar of my terminal say what command is running?

分類Dev

Bash script to monitor file change and execute command

分類Dev

Combine sed commands into one command in bash script

分類Dev

How to execute a command within a bash script?

分類Dev

Linux Bash Script, Single Command But Multiple Lines?

分類Dev

bash: Why are () causing error in script but not on the command line?

分類Dev

Bash script using mysql command with variables failing

Related 関連記事

  1. 1

    Running the script to invoke command in terminal

  2. 2

    Command works in terminal but not in bash script

  3. 3

    Running a shell script with and without "bash" command

  4. 4

    ~/.profile, ~/.bashrc, and ~/.bash_profile not running on new terminal start up

  5. 5

    Script running from terminal but not in crontab

  6. 6

    New Terminal bash file error

  7. 7

    Commands Working In Terminal, But Not In Bash Script

  8. 8

    Shortcut for running terminal command in VS code

  9. 9

    Running a program from terminal, "command not found"

  10. 10

    Printing the result of the script(running in background) on the terminal

  11. 11

    Running script and defining object value in terminal window

  12. 12

    Running bash script in a kubernetes pod

  13. 13

    bash_completion causing a 'command not found' in terminal

  14. 14

    echo/printf incomplete command at bash terminal

  15. 15

    -bash: 400:: command not found when open terminal

  16. 16

    Execute sed command in a bash script

  17. 17

    Bash script - unix - command not found

  18. 18

    exit a bash command in a script without exiting the script

  19. 19

    Using bash variables in perl command in bash script

  20. 20

    Shell script wrapper to prevent running command with no arguments?

  21. 21

    Running PHP works in Command Prompt but not Git Bash

  22. 22

    real-time search in terminal output stream; after running a command

  23. 23

    How to make the top bar of my terminal say what command is running?

  24. 24

    Bash script to monitor file change and execute command

  25. 25

    Combine sed commands into one command in bash script

  26. 26

    How to execute a command within a bash script?

  27. 27

    Linux Bash Script, Single Command But Multiple Lines?

  28. 28

    bash: Why are () causing error in script but not on the command line?

  29. 29

    Bash script using mysql command with variables failing

ホットタグ

アーカイブ