Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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

4 Answers 4

up vote 7 down vote accepted
$ ssh -t hostname "cd projects; exec bash"

you can use other shells instead of bash

share|improve this answer
    
Exactly what I needed. Thanks! –  Matt Williamson Sep 19 '10 at 6:10

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.)

share|improve this answer

Use expect to actually login and run the commands.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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