N
ndrw_cheung
Hi. Im using RHEL6 (version 6.5) on all servers and I came across a problem invoking a process in the background via ssh. The set up is as follows:
Server 1 :
Script : start.sh:
#!/bin/sh
ssh user1_AT_x.x.x.x t sudo /etc/init.d/test1
#note : I cannot post the "at" sign due to being a new user, so _AT_ is the at sign
Server 2 :
Script : /etc/init.d/test1:
#!/bin/sh
./runremote.sh &
user1 exist on both server 1 and server 2 has sudo privileges.
When we do (logged in as user1 and sudo on server 1)./start.sh from Server 1, the script runremote.sh is NOT invoked. I tried removing the & to run runremote.sh in the foreground. That works, but the start.sh hangs and will not close the ssh connection. I also tried the following variations, but none of them work the way I wanted:
nohup ./runremote.sh
nohup ./runremote.sh &
./runremote.sh > /var/log/runremote.log 2>&1
./runremote.sh < /dev/null > /var/log/runremote.log 2>&1
How should I change the contents of these scripts so that when I do ./start.sh, runremote.sh is invoked in the background and start.sh will close the ssh connection afterwards? If possible, I DONT want to use any additional software such as screen.
Thanks in advance for answering.
-Andrew
Continue reading...
Server 1 :
Script : start.sh:
#!/bin/sh
ssh user1_AT_x.x.x.x t sudo /etc/init.d/test1
#note : I cannot post the "at" sign due to being a new user, so _AT_ is the at sign
Server 2 :
Script : /etc/init.d/test1:
#!/bin/sh
./runremote.sh &
user1 exist on both server 1 and server 2 has sudo privileges.
When we do (logged in as user1 and sudo on server 1)./start.sh from Server 1, the script runremote.sh is NOT invoked. I tried removing the & to run runremote.sh in the foreground. That works, but the start.sh hangs and will not close the ssh connection. I also tried the following variations, but none of them work the way I wanted:
nohup ./runremote.sh
nohup ./runremote.sh &
./runremote.sh > /var/log/runremote.log 2>&1
./runremote.sh < /dev/null > /var/log/runremote.log 2>&1
How should I change the contents of these scripts so that when I do ./start.sh, runremote.sh is invoked in the background and start.sh will close the ssh connection afterwards? If possible, I DONT want to use any additional software such as screen.
Thanks in advance for answering.
-Andrew
Continue reading...