Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. import multiprocessing
  2. import paramiko
  3. def run_remote(node,cmd):
  4. print cmd
  5. ssh = paramiko.SSHClient()
  6. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  7. ssh.connect(node,username='root',password='ABCD1234')
  8. stdin, stdout, stderr = ssh.exec_command(cmd)
  9. return
  10.  
  11. def test1(node):
  12. print "Calling test1"
  13. cmd = 'cd /rscript; python test1.py'
  14. #cmd = 'cd /rscript; ./test1.py'
  15. x = run_remote(node, cmd)
  16.  
  17. def test2(node):
  18. print "Calling test2"
  19. cmd = 'cd /rscript; python test2.py'
  20. #cmd = 'cd /rscript; ./test2.py'
  21. x = run_remote(node, cmd)
  22.  
  23. def main(node,start_mon):
  24. #Using multiprocessing to start monitoring
  25. jobs = []
  26. if start_mon == 1:
  27. p = multiprocessing.Process(target=test1,args=(node,))
  28. d = multiprocessing.Process(target=test2,args=(node,))
  29. p.start()
  30. d.start()
  31.  
  32. else:
  33. #Stopping all monitoring process
  34. cmd = 'pkill test1'
  35. x = run_remote(node, cmd)
  36. cmd = 'pkill test2'
  37. x = run_remote(node, cmd)
  38.  
  39.  
  40.  
  41. Scripts to be executed on remote host:
  42. #test1.py
  43. #!/usr/bin/python
  44. import subprocess
  45. def test1(node,cmd):
  46. print node
  47. print cmd
  48. p = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE)
  49. output1, error = p.communicate()
  50. output = output1.rstrip()
  51. print output
  52.  
  53. test1(node,cmd)
  54.  
  55. #test2.py
  56. #!/usr/bin/python
  57. import subprocess
  58. def test2(node,cmd):
  59. print node
  60. print cmd
  61. p = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE)
  62. output1, error = p.communicate()
  63. output = output1.rstrip()
  64. print output
  65.  
  66. test2(node,cmd)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement