Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import multiprocessing
- import paramiko
- def run_remote(node,cmd):
- print cmd
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(node,username='root',password='ABCD1234')
- stdin, stdout, stderr = ssh.exec_command(cmd)
- return
- def test1(node):
- print "Calling test1"
- cmd = 'cd /rscript; python test1.py'
- #cmd = 'cd /rscript; ./test1.py'
- x = run_remote(node, cmd)
- def test2(node):
- print "Calling test2"
- cmd = 'cd /rscript; python test2.py'
- #cmd = 'cd /rscript; ./test2.py'
- x = run_remote(node, cmd)
- def main(node,start_mon):
- #Using multiprocessing to start monitoring
- jobs = []
- if start_mon == 1:
- p = multiprocessing.Process(target=test1,args=(node,))
- d = multiprocessing.Process(target=test2,args=(node,))
- p.start()
- d.start()
- else:
- #Stopping all monitoring process
- cmd = 'pkill test1'
- x = run_remote(node, cmd)
- cmd = 'pkill test2'
- x = run_remote(node, cmd)
- Scripts to be executed on remote host:
- #test1.py
- #!/usr/bin/python
- import subprocess
- def test1(node,cmd):
- print node
- print cmd
- p = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE)
- output1, error = p.communicate()
- output = output1.rstrip()
- print output
- test1(node,cmd)
- #test2.py
- #!/usr/bin/python
- import subprocess
- def test2(node,cmd):
- print node
- print cmd
- p = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE)
- output1, error = p.communicate()
- output = output1.rstrip()
- print output
- test2(node,cmd)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement