2

I want to run below mysql query on remote server in background.

nohup mysql -h10.0.100.1 -P3306 -utest -ppassword -Dcms -e "select * from table1 ;" & echo $!

When above command is execute manually from command line, I see process is running in background (table has records which would return response over 2 mins)

[root@TEST_Server]# ps -ef | grep mysql
root 11144 9227 19 17:44 pts/0 00:00:01 mysql -h 10.0.100.1 -P 3306 -utest -px xxxxxxx -Dcms -e select * from table1 ;

However when I use this code in python script, I don't see any process running in background. It is not executing intended mysql command Python code snippet:

 cmd = "nohup mysql -h10.0.100.1 -P3306 -uroot -ppassword -Dcms \
            -e \"select * from table1 ;\" & echo $!"  
 out, err, code = ssh_client.execute_sudo_command(["%s" % cmd])  
 print out

It returns the PID however I don't see that process is not really running in background for period of time it intended to run.

I have tried solution mentioned in https://github.com/brooklyncentral/brooklyn/issues/162 or http://en.wikipedia.org/wiki/Nohup

ssh localhost 'nohup mysqld > out 2> err < /dev/null & echo $! > pid.txt ; exit 0'

but it didn't worked out.

I am using python 2.7.6 and SSHClient for remote connection. Any suggestions to overcome this issue?

Ravi
  • 79
  • 2
  • 11

0 Answers0