You are not logged in.

#1 2011-08-21 04:16:38

cs_student
Member
From: Richmond, Virginia
Registered: 2010-04-22
Posts: 21

ssh script then run bash interactively?

I have a script, which I can not put on a remote server.  However, I would like to run it on the remote server using ssh. 

What I have been doing recently is

ssh -t host <<-EOF
  command1;
  command2;
  ...
  /bin/bash -i
EOF

It runs the commands correctly, but does not give me the bash prompt.

I can do

ssh -t host "command1; command2; bash"

The only issue, is that the commands has lots of characters in it, making escaping extremely complex (it's a 100 line script).

Any ideas as to how to accomplish this would be extremely helpful.

EDIT: also sorry if this is a nooby question.  Wasn't sure if should be in Newbie Corner or not

Last edited by cs_student (2011-08-21 04:17:18)

Offline

#2 2011-08-21 05:25:49

shoelace
Member
Registered: 2011-08-09
Posts: 5

Re: ssh script then run bash interactively?

Hi, I'm a freshman too. I ran a test, here is the code, hope it's gonna help

bt# touch test.txt
bt# echo "uname -r; pwd; who" >> test.txt 
bt# ssh -t 192.168.158.130 < test.txt          
root@192.168.158.130's password: 
3.0-ARCH
/root
root     tty1         2011-08-12 05:19
root     pts/2        2011-08-12 05:20 (:0)
root     pts/1        2011-08-12 05:20 (:0)
root     pts/0        2011-08-12 05:20 (:0)
bt# 
cs_student wrote:

I have a script, which I can not put on a remote server.  However, I would like to run it on the remote server using ssh. 

What I have been doing recently is

ssh -t host <<-EOF
  command1;
  command2;
  ...
  /bin/bash -i
EOF

It runs the commands correctly, but does not give me the bash prompt.

I can do

ssh -t host "command1; command2; bash"

The only issue, is that the commands has lots of characters in it, making escaping extremely complex (it's a 100 line script).

Any ideas as to how to accomplish this would be extremely helpful.

EDIT: also sorry if this is a nooby question.  Wasn't sure if should be in Newbie Corner or not

Offline

#3 2011-08-21 05:51:16

Stebalien
Member
Registered: 2010-04-27
Posts: 1,239
Website

Re: ssh script then run bash interactively?


Steven [ web : git ]
GPG:  327B 20CE 21EA 68CF A7748675 7C92 3221 5899 410C

Offline

#4 2011-08-21 06:32:23

cs_student
Member
From: Richmond, Virginia
Registered: 2010-04-22
Posts: 21

Re: ssh script then run bash interactively?

I'm able to execute the commands just fine.
for example

ssh host <<-EOF
uptime
uname -r
hostname
cat ~/public_html/.htaccess
# more commands
EOF

The above works great.

The issue is I want to run all of those commands, then switch to the interactive shell.

ie I would get an example output

ssh -t host <<-EOF
  uname -r
  # code to switch to bash
EOF

outputs
2.6.39-ARCH
[user@remote_host ~]$ <enter command>

The issue is when I pipe from a file or a here document it takes input from stdin rather than the keyboard.  I don't see it taking input from one then the other.
I'm unsure as how to accomplish this.

The only way I see to do it is

ssh -t host "`cat script.txt`"

where script.txt has /bin/bash -i in the corresponding place I wish to interact with shell through keyboard.  However, it causes a lot of issues with escape characters.  I'll just have to get over that.... : )

Last edited by cs_student (2011-08-21 06:34:19)

Offline

Board footer

Powered by FluxBB