ssh, cd to a dir, and and then do some work.

I want to do something like

#!/bin/bash
ssh name@computer 'cd /my/dir'

and then continue working in this directory.

Right now if I execute a script "myscript" containing the above, it just drops me back into the bash shell where I started, whereas I want to be able to do work and stuff on this other computer.

I know this command is being execututed because if I change the script to

#!/bin/bash
ssh name@computer 'echo blah > blah.txt'

blah.txt does get created on the remote computer.

So the main question is, how do I keep that remote session open rather than reverting back to my original session.

I tried

./myscript &

but that didn't work.

Obviously this is a pretty simple problem, but I figure if I can get this working I learn something that can be applied to solving more powerful scenarios.

Thanks for your help in advance!

I don't think you can do it like that.

I'm a little rusty but looking at my old scripts I called SSH or SCP everytime I wanted to do one thing.

print "scp $USER@$HOSTNAME:$PWD/$5 $4@$server:/tmp/$5"
scp $USER@$HOSTNAME:$PWD/$5 $4@$server:/tmp/$5
print "chmod 700 /tmp/$5"
ssh -l $4 $server chmod 700 /tmp/$5
print "ssh -l $3 $1 pdadmin -a <user>/tmp/$5"
ssh -l $4 $server /usr/bin/pdadmin -a <user>-p $PASSWORD /tmp/$5
print "ssh -l $4 $server rm /tmp/$5"
ssh -l $4 $server rm /tmp/$5

I'm not sure the connection will stay open. Maybe try running commands like this but I don't know.

ssh -l user myserver chmod 700 /tmp/$5; ls -lrt; date; uptime;

Hope this helps.

-X