Saeya Darsan
Saeya Darsan

Reputation: 31

Execute a command after opening a terminal in which ssh is used to log into remote machine

I wish to open a new terminal, ssh to a remote machine in the opened terminal which has to be kept open and a command has to be executed in this terminal in foreground.

The following command opens a new terminal in which a remote machine is logged in:

gnome-terminal --window-with-profile=NOCLOSEPROFILE -e "ssh -X $user@$IPaddress"

(Say 'ls' is the command to be executed in foreground in the terminal newly opened)I tried the following command:

gnome-terminal --window-with-profile=NOCLOSEPROFILE -e "ssh -X $user@$IPaddress&&ls"

But this command opened a terminal without ssh-ing into the remote machine, paused for a while and it closed. Let me know what is wrong in this command and how to correct it.

Upvotes: 1

Views: 4530

Answers (1)

dannysauer
dannysauer

Reputation: 3867

You're running ssh and then running ls after the ssh command exits. You need

"ssh -X $user@$host 'command to run on host'"

Upvotes: 2

Related Questions