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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh, cd to a dir, and and then do some work.
# 1  
Old 04-13-2006
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!
# 2  
Old 04-13-2006
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ssh agent forwarding in script did not work

Sorry for the wrong question. (2 Replies)
Discussion started by: hce
2 Replies

2. SuSE

SSH issue - can't get password less login to work

Hello, I can't seem to get the password less login to work on one of my SLES 11 servers. My ssh agent lets me login to all my other servers, which are Solaris 10, RHEL 5, and SLES 11 servers. Some servers mount my home directory and others don't. The server that I'm having an issue with doesn't... (7 Replies)
Discussion started by: bitlord
7 Replies

3. AIX

2nd SSH doesn't work with AD

Recently I decided to intall second daemon of SSH for Winbind users. I mean I have configuration AIX + Samba + AD and I can login to the server via SSH with AD accounts to 22 port without any problems. But now I have second installation of OpenSSH and don't understand why I can't do the same... (6 Replies)
Discussion started by: jess_t03
6 Replies

4. Shell Programming and Scripting

ssh does not work in script while running crontab

Hi All, I have prepared a small script to monitor few applications running on diff unix boxes(frontend/backed node1/node2 etc). ssh does not work for node2 when script executed from crontab..:wall: it work fine when i run it manually. Regards, Pavan (4 Replies)
Discussion started by: pavanchouksey
4 Replies

5. IP Networking

Setting to SSH home-PC from Work

Hello, My question is very basic for the settings to SSH my home PC from work. Home network two PC: Internet comes into my house through ISP modem and then the two PCs are connected with the router (Trendnet). The IPs for my PCs are How to set other stuffs for me to access my home PC from... (5 Replies)
Discussion started by: yifangt
5 Replies

6. Shell Programming and Scripting

SSH shell script does not work

Hello I have a Zabbix Server were Linux kernel version 2.6.26-2-amd64 is running. now my Question how can i make a script that does: - connect with ssh to a device - get the systeminfo (but only the interfaces, mac adresses, serialnumber and Software version) - write the output in a file ... (18 Replies)
Discussion started by: Fraggy
18 Replies

7. UNIX for Dummies Questions & Answers

SSH-KEYGEN doesn't work

Hi, Am running the following commands on our server to generate a key for passwordless SSH, however we are getting 100% blank key files. E.g. when looking id_dsa.pub or id_dsa they are 100% empty - the files get created, but contain no content and have a file size of 0b. mkdir ~/.ssh... (3 Replies)
Discussion started by: gjp
3 Replies

8. UNIX for Dummies Questions & Answers

Can't get SSH to work without password

Need some help on this!! I've been trying to get SSH to work without having to enter a password. I've found numerous articles on this and have tried the instructions, but am still getting prompted for a password. One thing to mention is that I'm using different IDs on the two servers. Here's... (2 Replies)
Discussion started by: bradtri1
2 Replies

9. UNIX for Dummies Questions & Answers

How does /export dir work?

In solaris I can switch to /export/appl/home or /appl/home to get to my home dir. If I switch to /export/apps as oppose to just /apps I see lots of other stuff. Can someone tell me the difference? Thanks (3 Replies)
Discussion started by: gillbates
3 Replies

10. UNIX for Dummies Questions & Answers

How does /export dir work?

In solaris I can switch to /export/appl/home or /appl/home to get to my home dir. If I switch to /export/apps as oppose to just /apps I see lots of other stuff. Can someone tell me the difference? Thanks (1 Reply)
Discussion started by: gillbates
1 Replies
Login or Register to Ask a Question