I am trying to ssh from one machine to another within a Python script (Nautilus script). It works with the following:

ssh -t user@server "cd /home/some/dir ; csh"

However I don't like the idea of hardcoding the shell type.

Is there a way to set cwd within the ssh command without the need to hardcode the shell type?

link|improve this question
Technically it was a python script ;-) – Johnsyweb May 30 '11 at 10:18
feedback

2 Answers

up vote 0 down vote accepted

Invoke $SHELL instead.

ssh -t user@server 'cd /home/some/dir ; exec "$SHELL"'
link|improve this answer
Thanks, worked like a charm! – umpirsky May 30 '11 at 13:39
feedback

You can do this like so...

ssh -t user@server "cd /home/some/dir ; bash"

Where bash is your desired shell.

link|improve this answer
Thanks, it works. Is there a way to auto-detect or ommit shell, so it go to default? I don't like the idea to hardcode it. – umpirsky May 30 '11 at 11:21
@umpiresky: I don't have an Ubuntu box on which to test this, but on *BSD I can do: ssh -t user@server "cd /home/some/dir ; login user" (where user is the username that you have provided to ssh). If your remote host has the same setup as localhost you could use ${SHELL} instead. YMMV. – Johnsyweb May 30 '11 at 11:30
@Johnsyweb Nope, login user ddn't work for me. I'm connecting from Ubuntu to FreeBSD, but it would be nice to work for any server. That's why I don't like the idea to hardcode shell type (csh in my case). – umpirsky May 30 '11 at 12:05
login user works for me on FreeBSD. – Johnsyweb May 30 '11 at 12:06
1  
Hm, maybe, yes. But we already have a working nautilus script, lets just make it better. Thank fou your valuable help. – umpirsky May 30 '11 at 12:42
show 4 more comments
feedback

Your Answer

 
or
required, but never shown

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