Remote script via SSH not executing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remote script via SSH not executing
# 1  
Old 10-14-2015
Remote script via SSH not executing

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

Code:
cd $JBOSS_HOME
NODENAME=xyz; IP_ADDR=`hostname`; MGMT_IPADDR=`hostname`; offset=0
nohup ./bin/standalone.sh -Djboss.node.name=$NODENAME -Djboss.server.base.dir=../$NODENAME -b $IP_ADDR -bmanagement $MGMT_IPADDR --server-config=standalone.xml -Djboss.socket.binding.port-offset=$offset -Dcom.sun.management.jmxremote.port=4001 &

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.

Code:
ssh server1 "sh ~/scripts/start_standalone.sh"
ssh server1 'sh ~/scripts/start_standalone.sh'
ssh server1 `sh ~/scripts/start_standalone.sh`
ssh server1 sh ~/scripts/start_standalone.sh

ssh server1 "~/scripts/start_standalone.sh"
ssh server1 ' ~/scripts/start_standalone.sh'
ssh server1 ` ~/scripts/start_standalone.sh`
ssh server1  ~/scripts/start_standalone.sh

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:
Mod Comment edit by bakunin: please use CODE- (not ICODE-) tags. Thank you.

Last edited by bakunin; 10-14-2015 at 09:44 AM..
# 2  
Old 10-14-2015
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:
Code:
ssh user@remote.host command

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.

I hope this helps.

bakunin
# 3  
Old 10-15-2015
Hello Oraclermanpt,

This is how it goes, the syntax of the command would be following

Code:
ssh <Optons> <username@IP/hostname> "Commands needs to be executed"

Provide Error/standOutput of the command it would be helpful to troubleshoot.

Example 1:-

Code:
[root@localhost ~]# /usr/bin/ssh -t -o stricthostkeychecking=no root@192.168.254.130 "ls -l"
root@192.168.254.130's password:
total 60
-rw-------. 1 root root  2697 Jul 20 21:47 anaconda-ks.cfg
-rw-r--r--. 1 root root 39935 Jul 20 21:47 install.log
-rw-r--r--. 1 root root  9084 Jul 20 21:45 install.log.syslog
Connection to 192.168.254.130 closed.

Example 2:-
Code:
[root@localhost ~]# /usr/bin/ssh -t -o stricthostkeychecking=no root@192.168.254.131 "/bin/sh /root/checkmemory.sh"
root@192.168.254.131's password:
             total       used       free     shared    buffers     cached
Mem:           498        462         35          0         37        252
-/+ buffers/cache:        172        325
Swap:         1023          0       1023
Connection to 192.168.254.131 closed.

Thanks
LND

Last edited by Don Cragun; 10-15-2015 at 05:34 AM.. Reason: Add CODE tags.
This User Gave Thanks to LND For This Post:
# 4  
Old 10-15-2015
Code:
-bash-3.2$ /usr/bin/ssh -t -o stricthostkeychecking=no jboss@server1 "ls -l"
total 12
drwxr-xr-x 13 jboss mware 4096 Sep 16 15:55 EAP-6.4.0
drwxr-xr-x  8 jboss mware   85 Sep 16 16:05 XYZ
drwxr-xr-x  6 jboss mware 4096 Sep 16 16:04 java
drwxr-xr-x  2 jboss mware 4096 Oct 15 09:26 logs
-rw-r--r--  1 jboss mware    0 Oct 14 09:16 nohup.out
drwxr-xr-x  2 jboss mware   39 Oct 15 09:33 scripts
-rw-r--r--  1 jboss mware    0 Oct 13 16:36 t1
Connection to server1 closed.

-bash-3.2$ /usr/bin/ssh -t -o stricthostkeychecking=no jboss@server1 "/bin/sh ~/rootmemory.sh"
              total        used        free      shared  buff/cache   available
Mem:           3792         823         264          64        2704        2657
Swap:          8191           0        8191
Total:        11984         823        8456
Connection to server1 closed.

Invoke server1 script from server2

there is nohup in remote script shown below.

Code:
cd /apps/EAP-6.4.0
NODENAME=xyz; IP_ADDR=`hostname`; MGMT_IPADDR=`hostname`; offset=0
nohup ./bin/standalone.sh -Djboss.node.name=$NODENAME -Djboss.server.base.dir=../$NODENAME -b $IP_ADDR -bmanagement $MGMT_IPADDR --server-config=standalone.xml -Djboss.socket.binding.port-offset=$offset -Dcom.sun.management.jmxremote.port=4001 &
sleep 10

If I add sleep command in above.
Code:
ssh server1 sh ~/scripts/start_standalone.sh </dev/null >~/root-backup.log 2>&1 &

runs as backend on server2. even I kill backend process on server2. java process runs on server1(remote host).

remove sleep command doesn't start remote process.

---------- Post updated at 03:49 PM ---------- Previous update was at 11:24 AM ----------

issue is resolved. This may help others.

Code:
ssh server1  " sh ~/scripts/start_standalone.sh >console.log 2>&1"

Remote script

copied contents of .bash_profile to .bashrc

Code:
cd $JBOSS_HOME
NODENAME=xyz; IP_ADDR=`hostname`; MGMT_IPADDR=`hostname`; offset=0
nohup ./bin/standalone.sh -Djboss.node.name=$NODENAME -Djboss.server.base.dir=../$NODENAME -b $IP_ADDR -bmanagement $MGMT_IPADDR --server-config=standalone.xml -Djboss.socket.binding.port-offset=$offset -Dcom.sun.management.jmxremote.port=4001 &

SmilieSmilieSmilieSmilieSmilie

Last edited by oraclermanpt; 10-15-2015 at 12:33 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue in executing cat (remote ssh)

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)
Discussion started by: close2jay
5 Replies

2. Linux

Executing a script in remote machine through ssh

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)
Discussion started by: sanvel
5 Replies

3. UNIX for Dummies Questions & Answers

Executing a script in remote server

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)
Discussion started by: Girish19
1 Replies

4. Shell Programming and Scripting

Executing remote commands via ssh

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)
Discussion started by: moshesa
5 Replies

5. Shell Programming and Scripting

executing commands in remote server using ssh

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)
Discussion started by: maitree
7 Replies

6. Shell Programming and Scripting

executing command in a remote machine through ssh - shell script

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)
Discussion started by: rateeshkumar
1 Replies

7. Shell Programming and Scripting

Executing remote application using ssh without full reference to its location

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)
Discussion started by: jangozo
6 Replies

8. UNIX for Dummies Questions & Answers

how to stay in remote shell after executing commands in ssh?

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)
Discussion started by: hplonlien
1 Replies

9. Shell Programming and Scripting

Executing a script on a remote system via SSH

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)
Discussion started by: DeCoTwc
2 Replies

10. Shell Programming and Scripting

Executing awk in a remote server using ssh

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)
Discussion started by: karthikv
2 Replies
Login or Register to Ask a Question