sms_shelll

# -*- coding: UTF-8 -*-
__author__ = 'EX-PENGFEI913'


import time,paramiko,re,StringIO,unicodedata


def exec_shell(command):


    f = StringIO.StringIO()
    header_match = '(\[.+?@.+?\s.+?\]\$)'
    ssh.send(command+'\n')
    while True:
        out = ssh.recv(1024)
        print out,
        f.write(out)
        header_list = re.findall(header_match, out)
        if header_list and out.strip().endswith(header_list[-1]):
            break
    return f


def check_ip(content):


    ips = re.findall('\d+\.120\.\d+\.\d+',content)
    return ips


if __name__ == '__main__':


    host = '10.59.72.161'
    port = 22
    username = 'www'
    password = '2V4B6cw9B0'


    s = paramiko.SSHClient()
    s.load_system_host_keys()
    s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    s.connect(host, port, username, password)
    ssh = s.invoke_shell()
    a=exec_shell('ps aux|grep send_message')
    #b=exec_shell('ps aux|grep send_result')


    stdin, stdout, stderr = s.exec_command('ps aux|grep send_message')
    #stdin, stdout, stderr = s.exec_command('ps aux|grep send_result')


    c=stdout.readlines()[1]
    #c=stdout.readlines()[1]


    files = unicodedata.normalize('NFKD', c).encode('utf-8', 'ignore')
    print type(files)
    files = files.split(' ')
    files_List = []
    for i in range(len(files)):
        files_List.append(files[i])
    print files_List[6]


    command='kill '+' '+ files_List[6]
    print command
    exec_shell(command)
    exec_shell('ps aux|grep send_message')
    #exec_shell('ps aux|grep send_result')


    #ips = check_ip(s.getvalue())
    #exec_shell('cat '+ips[0]+'/log/duobao.log')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值