I have worked on multiple scenarios to execute remote script via ssh.
This problem I am not able to resolve.
2 linux hosts. Server1, Server2
on Server1 I have script called ~/scripts/start_standalone.sh
XXXX
above code runs properly when executed locally on server1 starts standalone instance.
if I invoke ~/scripts/start_standalone.sh remotely from server2. its not starting standalone process.
Below I tried from server2.
If I put some echo statements in the script they are executed from server2. That means remote executing of the script is working but some commands are skipped.
Any pointers will be helpful.
Thanks for reading my post.
Moderator's Comments:
edit by bakunin: please use CODE- (not ICODE-) tags. Thank you.
There may be several problems and you are the only one to find out, because you have posted no error messages or other diagnostic output. Take the following as pointers:
- maybe for some commands a terminal is required or wrongly allocated. Search the man pages of ssh for "-n" and/or "-q" and decide if this applies to your situation. In any case you might want to include the -o BatchMode = yes into your ssh-command.
- try an interactive session with the machine where it doesn't work: if the keys are not exchanged and/or if the system is not in your known_hosts file you might experience problems. To avoid the "The authenticity of ... Are you sure you want to continue connecting (yes/no)?"-message you need to set "StrictHostKeyChecking" to "no" in the options.
- specify an explicit user to use in the ssh-call:
will connect as "user" to "remote.host" and then issue "command" as this user. Otherwise you are relying on the user who issed the command on the local host, which may or may not be what you want.
- you use a variable "JBOSS_HOME" without defining it in the script. It might be that you are not running the same initialisation scripts if your session is not interactive. In general it is better to set explicitly in a script what you use and never use relative pathes at all.
There are most probably several more possibilities of what could have gone wrong, but this is all guessing, so the above list is incomplete in nature.
Hi,
I need to ssh remotely to a machine and cat a file assign the value to a variable
Script:
#!/bin/bash -x
value=`cat config.txt`
echo "$value"
ssh me@xxx.host.com "valu='cat /export/home/test.md5'; echo "$valu"" | tee
Execution:
$ ./x
++ cat config.txt
+ value='touch me'
+... (5 Replies)
How to execute a script in remote machine through ssh
I have a script test.sh which does some backup activity in remote machine. Wanted to keep backup also in remote machine.
ssh -l username <remote machine> "commands to be exceuted as ; separted"
but how to put the script in the place of... (5 Replies)
Hi All,
I have 2 servers A and B. I need to connect to server B from server A and execute a shell script in B which will create some files and i need to copy those files back to server A.
Required easiest possible for perfoming above task. (1 Reply)
Hi,
I'm tryin to write a script that will collect information about a remote servers, put them into variables and print them to screen.
# /usr/bin/bash
ls $1 > /dev/null 2>/dev/null
if
then
echo "$1 is file"
for server in $(cat $1)
do
# echo $server
... (5 Replies)
I have some commands which need to be executed in remote machine.
I have Linux Server from where I need to connect to Solaris server using ssh and then declare some variable over there and run some commands. I don't want to call a script which is present in Solaris server from Linux server... (7 Replies)
Hi All,
i have two machines like x and y . my requirement is i should connect to machine Y from x through ssh connection . and do some operation such as copy and move and delete files in Y machine .
i tried with this code but it is doing in machine x only . and i need to exit from Y when... (1 Reply)
Hello again :) ,
My script has an ssh command to run a script on a remote machine. The script has commands such as sqlplus and unzip. However, the return I get in my own terminal says it can't find sqlplus and unzip.
the ssh command is:
ssh user@host "cd ScriptDir; ./Script.sh"
and the... (6 Replies)
the ssh calling convention:
ssh <server>
If I put commands in the section, ssh will execute them immediately after logging in and return to local shell. I want to stay in the remote shell after executing these commands. How can I achieve this?
Thanks for all. (1 Reply)
Hello all,
I have a relatively simple script I wrote to generate a count of errors broken down. What I would like to do is execute this script from another server so that I don't actually have to log in to the server to run the check.
The script on what we'll call "Server A" is:
... (2 Replies)
Hello Everybody,
I'm facing a weird problem with the awk command.
I'm trying to execute a simple awk command as follows,
echo 1 2 | awk '{print $2}'
This command prints the output 2.
When i try to execute the same command in a remote server using ssh as follows,
ssh user@host... (2 Replies)