0

When running a script on remote server, I need prevent the nohup output from the remote server to be displayed on the ssh server.

I am running below command line to run a script on remote server.

ssh user@server.com "cd /cpmapps/soa/operations/bin/; ./restart_soa.sh stop"

But when it runs, it unpredictably displays the nohup output of a command in the 'remote server script'. Here's the excerpt from the script where you can see that the command is supposed to run in the background.

  echo " Starting the weblogic Managed Server SOA"
nohup ./startManagedWebLogic.sh soa_server1 https://server:7002 & > soa.out 1>&2&
sleep 180
ps_count=`netstat -an | grep 7002 | egrep "LISTEN" |grep -v grep|wc -l`
echo ps_count $ps_count
if [ "$ps_count" -ne "0" ];then
echo "managed server is up"
echo "proceeding with starting BAM"
else
echo "Failed to start weblogic"
exit 1
fi

However, when I run the script on the server where the script is located, it runs as predicted. As shown below.

Home Server Home Server

While when I run it from the remote server, it shows output for the command too. As shown below.

Remote Server enter image description here

How can I make it run on the remote server the same way as it is running on the home server? Would really appreciate any help on this.

user2373210
  • 461
  • 2
  • 5
  • 16

2 Answers2

1

Call your script this way:

nohup ./startManagedWebLogic.sh soa_server1 https://server:7002 > soa.out 2>&1 &

This will write the output to file soa.out and 2>&1 will direct all the STDERR as STDOUT writing it to soa.out, the last & will run the job in the background.

Check also this answer: https://stackoverflow.com/a/10408906/1135424

nbari
  • 25,603
  • 10
  • 76
  • 131
0

Another way is to redirect your nohup out to null device. e.g: nohup ./script.py > /dev/null &