标签:chown community ibm stderr false uname roo 手动安装 proc
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() version=platform.version().split(‘.‘)[0] if ‘aix‘ not in platform.platform().lower() or version not in (‘4‘,‘5‘): print ‘目前只支持aix4和aix5系统的安装,该机器不在支持的系统范围内‘ sys.exit(1) if not os.path.exists(data_path): os.makedirs(data_path) if not os.path.exists(pkg_path): os.makedirs(pkg_path) def is_empty(path): files=os.listdir(path) for filee in files: f=str(path+filee) if os.path.isdir(f): if os.listdir(f): return False return True if not os.path.exists(install_base): os.makedirs(install_base) elif not is_empty(install_base): print ‘{}目录下已有文件,请确认!‘.format(install_base) sys.exit(1) for i in pkg_file: code, res = run_cmd(‘tar -zxvf {} -C {}‘.format(i, pkg_path)) if code: print ‘解压异常‘ print res sys.exit(1) arch=platform.uname()[2] if version==‘4‘: file_name = ‘nmon_{}{}‘.format(version arch) else: install_path_tmp = os.path.join(pkg_path, file_name) install_path = os.path.join(install_base, file_name) shutil.move(install_path_tmp, install_path) code, res = run_cmd(‘chown root:root {}‘.format(install_path)) if not code: print ‘已安装至{}‘.format(install_path) else: print res sys.exit(1) cronfile = ‘/var/spool/cron/root‘ n = set([‘0 0 * * * {} -fT -m {} -s {} -c {}‘.format(install_path, data_path, save_day, count), ‘0 0 * * * find {0} -mtime +{1} -name "*.nmon" -exec rm -rf {{}} \;‘.format(data_path, gap_time)]) with open(cronfile, ‘r‘) as f: content = f.readlines() content=set([i.strip() for i in content]) n=n-content if n: n=[ i+‘\n‘ for i in n ] with open(cronfile, ‘a‘) as f: f.writelines(n) print ‘安装并配置成功‘
标签:chown community ibm stderr false uname roo 手动安装 proc
原文地址:https://www.cnblogs.com/slqt/p/10494493.html