- 求职 : 其它语言研发
- 论坛徽章:
- 0
|
本帖最后由 killedman 于 2017-05-18 22:53 编辑
- #!/usr/bin/env python3
- #-*- coding:utf-8 -*-
- #stop dpat
- import paramiko
- import time
- username='username'
- password='password'
- ip='192.168.1.1'
- #建立连接
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(hostname=ip, port=22, username=username, password=password,timeout=10.0)
- #打印分隔符
- print(' Server: ' + ip)
- stdin, stdout, stderr = ssh.exec_command("jstorm list|grep -A 1 dpat-test|grep status")
- test_name = stdout.readline()
- print(test_name)
- #stop dpat-test,while循环直到状态由ACTIVE变为KILLED
- #while('ACTIVE' in test_name):
- if('ACTIVE' in test_name):
- print(time.asctime(time.localtime(time.time())))
- stdin, stdout, stderr = ssh.exec_command('cd /run/ayena/dpat/;sh stop-dpat.sh')
- #神奇的5秒钟,上一条命令添加timeout参数不知道为什么不起作用
- time.sleep(5)
- print(time.asctime(time.localtime(time.time())))
- stdin, stdout, stderr = ssh.exec_command('jstorm list|grep -A 1 dpat-test|grep status')
- print(stderr.read())
- test_name = stdout.readline()
- print(test_name)
- print("begin stoping run-dpat: " + time.asctime(time.localtime(time.time())))
- while('KILLED' in test_name):
- time.sleep(10)
- stdin, stdout, stderr = ssh.exec_command('jstorm list|grep -A 1 dpat-test|grep status')
- test_name = stdout.readline()
- if test_name is '':
- print(" end stoping dpat-test : " + time.asctime(time.localtime(time.time())))
- print('stop dpat-test process success')
- #关闭连接
- ssh.close()
复制代码 |
|