Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

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

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 04-13-2006
x96riley3 x96riley3 is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 16 April 2015, 10:39 AM EDT
Location: Nashville
Posts: 81
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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 01:35 PM.