I wish to ssh into a server in my department, cd
to a directory automatically, and hopefully be able to auto-run other commands if I want. I have tried several ways that have worked for lots of people on stack-overflow, but they did not work for me.
I have tried the methods from the following threads:
In particular, I have tried:
1. ssh one-liner
ssh -t user@domain.com 'cd /some/path; bash -l'
and
2. using the expect
script
#!/usr/bin/expect -f
spawn ssh $argv
send "cd /some/path\n"
interact
Both codes look fine, and have worked for people in the threads. However, they did not work for me.
The problem, I expect, lies in the fact that the department server asks me automatically about my terminal type as I login, preventing my auto-commands to be run properly.
$ ssh -t user@domain.com 'cd /some/path; bash -l'
Terminal type? [xterm-256color]
After hitting , it takes me into the home directory as if I haven't cd
yet.
The second way gives a similar result.
How can I get over this? Thank you very much in advance!