You are not logged in.
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
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#
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
There are several ideas here: http://stackoverflow.com/questions/4664 … h-function.
Offline
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