zoukankan      html  css  js  c++  java
  • aix安装nmon

    aix5310以上都系统自带了nmon,其他低版本需要手动安装

    软件包下载地址https://www.ibm.com/developerworks/community/wikis/home?lang=en#/wiki/Power%20Systems/page/nmon

    安装脚本如下

    import os
    from subprocess import Popen, PIPE, STDOUT
    import sys
    import platform
    import shutil


    def run_cmd(cmd, cwd=None, env=None, run_as=None):
    if not sys.platform.startswith('win') and run_as and run_as != 'root':
    cmd = 'su - {} -c "{}"'.format(run_as, cmd)
    p = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT, stdin=PIPE, cwd=cwd, env=env)
    stdout, _ = p.communicate()
    return p.returncode, stdout.strip()


    if 'aix' not in platform.platform().lower():
    print '只支持aix系统的安装,该机器不是aix系统'
    sys.exit(1)

    cmd = 'oslevel -r'
    version_list={'5':5309,'6':6102,'7':7000}
    code, res = run_cmd(cmd)
    if not code and res:
    key=res[0].strip()
    value=res.split('-')[1].strip()
    if version_list.get(key) and int(key+res[1].strip()+value)>=version_list.get(key):
    print '当前版本是',res
    else:
    print '当前版本是',res,'该操作只支持5309+,6102+,7100+的版本'
    sys.exit(1)
    else:
    print '获取版本失败'
    sys.exit(1)

    cmd = 'ps -ef |grep nmon|grep -v grep'
    code, res = run_cmd(cmd)
    if res:
    print '已有nmon在运行'
    sys.exit(1)

    cmd = 'which nmon'
    code, res = run_cmd(cmd)
    if code:
    print '该系统未安装nmon'
    sys.exit(1)

    if not os.path.exists(data_path):
    os.makedirs(data_path)


    def is_empty(path):
    for root, dirs, files in os.walk(path):
    if len(files) != 0:
    return False
    return True


    cronfile = '/var/spool/cron/crontabs/root'
    run_cmd('cp {0} /tmp/crontab_root.`date +%F_%T`'.format(cronfile))


    content = '0 0 * * * nmon -fT -m {0} -s {1} -c {2} '
    '0 0 * * * find {1} -mtime +{3} -name "*.nmon" -exec rm -rf {{}} ; '.format(data_path, save_day, count,gap_time)


    has_content=False
    if not os.path.exists(cronfile):
    with open(cronfile, 'w') as f:
    f.writelines(['### for nmon install ### ',content,'### for nmon install ### '])
    else:
    real_content=[]
    with open(cronfile, 'r') as f:
    raw_content = f.readlines()

    flag=0
    for i in raw_content:
    flag = flag % 2
    if '### for nmon install ###' in i.strip():
    flag += 1
    if flag==0:
    real_content.append(i)

    with open(cronfile, 'w') as f:
    f.writelines(real_content)
    with open(cronfile, 'a') as f:
    f.writelines(['### for nmon install ### ',content,'### for nmon install ### '])

    print '安装并配置成功'




      

  • 相关阅读:
    mysql联合索引命中条件
    Shiro知识初探(更新中)
    Java中使用MongoTemplate进行分批处理数据
    Java中String时间范围比较
    使用ReentrantLock
    使用Condition
    python的坑--你知道吗?
    python基础--函数全解析(1)
    CSS基本语法及页面引用
    HTML学习汇总
  • 原文地址:https://www.cnblogs.com/slqt/p/10494493.html
Copyright © 2011-2022 走看看