2

I can do this: ssh hostname "cd projects" but it exits after it changes directory. How can I do that, but leave the ssh shell open so now I am in projects? I also might want to open a mysql shell afterwords.

  • Ummm... ssh hostname <cr> cd projects <cr> is the same number of keystrokes and accomplishes exactly what you want to do... unless I'm missing something? – David Mackintosh Sep 17 '10 at 3:23
  • Trying to automate it.... – Matt Williamson Sep 17 '10 at 3:29
  • Is it the same command every time? – JakeRobinson Sep 17 '10 at 5:12
7
$ ssh -t hostname "cd projects; exec bash"

you can use other shells instead of bash

3

You can create ~/.ssh/rc (on the remote host) with commands you want run each time the user logs in. It will be executed prior to invocation of the shell.

See the sshd man page, section SSHRC, for more information (note especially the comments regarding necessity for setup of xauth if this file is deployed.)

1

Use expect to actually login and run the commands.

0

I don't understand well what you need, but maybe screen can help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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