ssh, cd to a dir, and and then do some work. | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

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

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-13-2006
tphyahoo tphyahoo is offline
Registered User
 
Join Date: Apr 2006
Last Activity: 27 May 2008, 6:39 PM EDT
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
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!
Sponsored Links
    #2  
Old 04-13-2006
x96riley3 x96riley3 is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 20 May 2013, 3:39 PM EDT
Location: Nashville
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How csf &apf work ? nitin09 UNIX for Advanced & Expert Users 0 02-27-2008 07:36 AM
Script doesn't work, but commands inside work cheongww UNIX for Dummies Questions & Answers 2 11-14-2006 09:52 PM
Will this work? Ypnos Shell Programming and Scripting 5 07-24-2003 01:51 PM



All times are GMT -4. The time now is 09:39 AM.