I need to run an infinite bash loop for background monitoring task on a remote server. I am using python Paramiko for this work and run the following command:
s = paramiko.SSHClient()
s.load_system_host_keys()
s.connect(hostname, port, username, password)
cmd = 'bash -c "while :; do cat /some/file >>/tmp/sca.mon; sleep 1 ; done" &'
(stdin, stdout, stderr) = s.exec_command(cmd)
However, this does not work for what ever reason. It just stuck at exec_command
line. How can I force the paramiko to leave the remote server when it submit the background bash command and start execute next like ?
Note: I have tried nohup bash -c
as well but it does not work as long as I use &
to push the command running in the background on the remote server.