user2928822
user2928822

Reputation: 35

How to run a nohup command present in a variable using ssh?

I am new to Linux. I stored a command in a variable say

a="nohup ./startWebLogic.sh &".

I need to run this command on remote server along with few other commands. I have tried as follows...

ssh user@server << EOF
few shell commands then
eval "$a"
EOF

When I run the above script, it doesn't do anything after logging in the remote server, neither it throws me any error, nor it runs the nohup command..my intention is to start the WebLogic on the remote server using nohup...thanks!!

Upvotes: 2

Views: 2534

Answers (3)

Tommy Le Jonkes
Tommy Le Jonkes

Reputation: 1

I had a similar problem, try create a file e.g a.sh:

#!/bin/bash
nohup ./startWebLogic.sh &
exit 0

and set a="./a.sh"

Upvotes: 0

user2928822
user2928822

Reputation: 35

Worked with a="nohup ./startWebLogic.sh >> nohup.out 2>&1 &"

Upvotes: 0

Igor Chubin
Igor Chubin

Reputation: 64563

You just can run it so:

ssh user@server "$a"

The variable $a will be expanded and passed to the shell at server.

If you want to use <

ssh user@server sh -s <<EOF
few shell commands then
eval "$a"
EOF

Please note sh -s here and that, that I removed the space between << and EOF.

Upvotes: 1

Related Questions