Combine multiple commands

I have the following sh-script:

    konsole -T todo -e vi todo.txt &
    konsole -T window1 -e ssh user@server &
    konsole -T window2 -e ssh user@server2 -e cd directory &

The first two lines are working fine. The first opens a txt-file, the second opens a ssh-connection.
The third line should open a ssh-connection and then go to a dirctory, but it does not work. Can someone please tell me if it is possible to combine these two command in a script ?

Not being familiar with konsole , I'd guess you could combine several commands in a "list", i.e. adding them after another separated by semicolons, eventually enclosed in (double) quotes. On top, ssh does allow to specify a command as a parameter. Did you consider that?

Are you opening a remote session and then changing directory on that remote session? If you are you are doing it wrong as the -e option to ssh is not a "run this shell command" option.

Are you trying to keep the konsole open after the remote session closes, but change directory?

Andrew

From the 'konsole' man page:

-e command

Execute command instead of the normal shell.

         This option will catch all following arguments passed to Konsole, and execute it as command. So this option should always be used as the last option.

From this, I would conclude that in your last example konsole is actually executing the command

ssh user@server2 -e cd directory

which should cause an error message to be displayed (which you probably don't see, because the konsole window will close too quickly).

@Andrew

So what is the right way then ? Can you give me a few keywords ?

Yes, I wanna keep the konsole open and then work in it.

One wonders what the point of changing directory is supposed to be. If that is all you do, then then you command will complete and the ssh will terminate putting you back to the client and you have achieved nothing except you would get an error if the directory was not accessible.

What are you really trying to do? Some context might help us understand your real purpose.

Kind regards,
Robin

@rbatte1: I guess the OP poster wants a new console window opened, which is logged into a different host AND placed in a certain directory - at least this would make sense, but we don't know for sure.

Of course there are several ways to achieve this, but unless we don't know the exact requirements, there is no point in making suggestions.