互联网服务python自动化运维

【核心议题】Python 在自动化运维工作方面能帮你做什么,有哪些经验值得分享?

        Python 语言越来越火,在自动化运维的今天,Python 俨然已经成为一个运维工程师不可缺少的一个技能手段,从近两年的招聘就可以看出,Python的重要程度不言而喻。        今天我们就来聊聊,Python 在我们运...显示全部

        Python 语言越来越火,在自动化运维的今天,Python 俨然已经成为一个运维工程师不可缺少的一个技能手段,从近两年的招聘就可以看出,Python的重要程度不言而喻。

        今天我们就来聊聊,Python 在我们运维工作上在哪些方面可以帮到我们,你又用python解决了什么问题,现在开源产品中哪些python 产品可以应用到我们的企业当中来,你对使用python有哪些疑惑,欢迎探讨。

收起
参与17

查看其它 4 个回答powertiandi的回答

powertiandipowertiandi联盟成员系统架构师李宁(中国)体育用品有限公司

分享一个使用Python Fabric 的小例子:


#!/usr/bin/python

from fabric.api import *

from fabric.colors import *

env.shell=\"/bin/sh -c\"  

env.roledefs={

\'was100\':[\'10.1.9.169\',\'10.1.9.170\'],

}

env.user=\'username\'

env.password=\'password\'

errinfo=\'err.info\'

get_info=open( errinfo, \'w\')

get_info.truncate()

get_info.close()

get_info=open( errinfo, \'a\')

def exec_file(shell_file):

    shell=\"\"

    try:

        fd=open(shell_file,\"r\")

        shell=fd.read()

    except:

        print \"can\'t open file\"

        exit()

    fs=run(shell)

    if fs.strip()!=\'\':

        get_info.write(env.host+\' the system error report : \\n \' + fs + \'\\n\' )

        get_info.flush()

    else:

        pass

cmd_fd=\'script/exe_cmd.sh\'

@roles(\'was100\')

def deploy():

    exec_file(cmd_fd)



[root@monitor script]# cat exe_cmd.sh

errpt -dH

直接可以使用

互联网服务 · 2017-04-14
浏览3522
  • 能解释下这段代码的作用吗?
    2017-06-26
  • 这个例子中的代码是用来检测aix 操作系统层面的硬件报错信息的,如果有硬件报错就会写入到文件,后续可以配合邮件发出。
    2017-06-26

回答者

powertiandi
系统架构师李宁(中国)体育用品有限公司
擅长领域: 存储服务器灾备

powertiandi 最近回答过的问题

回答状态

  • 发布时间:2017-04-14
  • 关注会员:7 人
  • 回答浏览:3522
  • X社区推广