首页 > 系统相关 >python脚本check linux

python脚本check linux

时间:2022-11-15 22:55:50浏览次数:48  
标签:trans grep python cmd apps linux print property check

check脚本:

import paramiko
import ConfigParser
import sys
# -*- coding: UTF-8 -*-
username="root"
pwd="YDYP1F1@flzx3kc"
host_ip=[]
reload(sys)
sys.setdefaultencoding('utf8')

with open("/tmp/hostip.txt") as hostips:
    for hostip in hostips:
        host_ip.append(hostip.strip())
print(host_ip)
print("---------------------------------------------------------------------------------------")
print("---------------------------------------------------------------------------------------")
cf=ConfigParser.ConfigParser()
cf.read("/tmp/cmd.txt")

def get_ssh(ip,username,pwd,cmd_trans):

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(ip, 22, username, pwd)

    stdin,stdout,stderr=ssh.exec_command(cmd_trans)
    #print(ip,stdout.readlines())
    bb=stdout.readline().strip()
    #print("------",bb)
    cpuinfo[ip]=bb

cmd_lists=cf.sections()

for cmd_list in cmd_lists:
    #print(cmd_list)
    cpu = {}
    cpuinfo = {}
    key=[]
    cmd_trans = cf.get(cmd_list, 'cmd_trans')
    property=cf.get(cmd_list,'property')
    #print(cmd_trans)
    for ip in host_ip:
        get_ssh(ip, username, pwd, cmd_trans)
   # print(property,'\033[1;34;43m %s nihao \033[0m' % cpuinfo)
    print(property)
    for key, value in cpuinfo.items():
      print(key+'  '+'\033[1;34;43m %s  \033[0m' % value)
    print("-----------------------------------------------------------------------------------")
    print("-----------------------------------------------------------------------------------")

cmd.txt

[CPU_ALL_thread]
cmd_trans=cat /proc/cpuinfo | grep processor | wc -l
property=检查总CPU线程


[one_cpu_thread]
cmd_trans=cat /proc/cpuinfo | grep 'cpu cores'  | uniq | awk '{print $4}'
property=检查单个CPU线程

[CPU_work_pattern ]
cmd_trans=cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor  | grep performance | wc -l
property=CPU工作模式(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor  | grep performance | wc -l)

[fdisk_num]
cmd_trans=fdisk  -l | grep 'Disk /dev' | wc -l
property=fdisk_num(fdisk  -l | grep 'Disk /dev' | wc -l)

[raid1]
cmd_trans=/opt/MegaRAID/storcli/storcli64 /c0/vall  show | grep "RAID1"
property=raid1

[raid6]
cmd_trans=/opt/MegaRAID/storcli/storcli64 /c0/vall  show | grep "RAID6"
property=raid6

[free_g]
cmd_trans=free -g | grep Mem | awk '{print $2}'
property=free_size_g

[bond0_speed]
cmd_trans=ethtool bond0 | grep Speed | awk '{print $2}'
property=bond0_speed

[bond1_speed]
cmd_trans=ethtool bond1 | grep Speed | awk '{print $2}'
property=bond1_speed

[bond2_speed]
cmd_trans=ethtool bond2 | grep Speed | awk '{print $2}'
property=bond2_speed


[bond0_mode_1]
cmd_trans=cat /etc/sysconfig/network-scripts/ifcfg-bond0 | grep "mode=1"
property=bond0_mode_1

[bond0_mode_6]
cmd_trans=cat /etc/sysconfig/network-scripts/ifcfg-bond0 | grep "mode=6"
property=bond0_mode_6_ok

[bond1_mode_4]
cmd_trans=cat /etc/sysconfig/network-scripts/ifcfg-bond1 | grep "mode=4"
property=bond1_mode_4

[route_n]
cmd_trans=route -n | grep 10.206.196.254 
property=route_n

[docker_v]
cmd_trans=docker -v | awk '{print $3}' | sed 's/,//g'
property=docker_v

[numa]
cmd_trans=dmesg | grep -i numa | grep "No NUMA" | wc -l
property=numa_ok_1(dmesg | grep -i numa | grep 'No NUMA' | wc -l)


[chronyd_status]
cmd_trans=systemctl status chronyd.service | grep running 
property=chronyd_status

[date_R]
cmd_trans=date -R | grep '+0800' | wc -l
property=date_R_OK_1

[date]
cmd_trans=date |grep CST | wc -l
property=date_OK_1

[hostname]
cmd_trans=hostname
property=hostname


[firewalld_ok_1]
cmd_trans=systemctl status firewalld  | grep dead 
property=firewalld

[selinux]
cmd_trans=/usr/sbin/sestatus -v | grep disabled 
property=selinux

[system]
cmd_trans=cat /etc/redhat-release
property=系统

[uname]
cmd_trans=uname -r
property=uname内核

[users_apps]
cmd_trans=cat /etc/passwd | grep apps
property=usrs_apps用户

[users_deployer]
cmd_trans=cat /etc/passwd | grep deployer
property=users_deployer用户

[dir_apps]
cmd_trans=ls -l / | grep apps
property=dir_apps_775

[users_apps]
cmd_trans=cat /etc/passwd | grep apps
property=usrs_apps用户

[users_apps]
cmd_trans=cat /etc/passwd | grep apps
property=usrs_apps用户

[locale]
cmd_trans=locale | grep 'en_US.UTF-8'  | wc -l
property=locale(locale | grep 'en_US.UTF-8'  | wc -l)

[sys_per1]
cmd_trans=cat /etc/sysctl.conf | grep net.netfilter.nf_conntrack_tcp_be_liberal
property=sys_per1

[sys_per2]
cmd_trans=cat /etc/sysctl.conf | grep fs.pipe-user-pages-soft
property=sys_per2

[sys_per3]
cmd_trans=cat /etc/sysctl.conf | grep fs.pipe-max-size
property=sys_per3

[apps_clouddb]
cmd_trans=lsblk | grep '/apps/clouddb'
property=apps_clouddb

[apps_sharedstorage]
cmd_trans=lsblk | grep '/apps/sharedstorage'
property=apps_sharedstorage

[apps]
cmd_trans=lsblk | grep '/apps'
property=apps
View Code

host.ip

 

标签:trans,grep,python,cmd,apps,linux,print,property,check
From: https://www.cnblogs.com/aroin/p/16894342.html

相关文章

  • Python读取写入txt内容
    Python读取、写入txt内容withopen("test.txt","r")asf:#打开文件data=f.read()#读取文件print(data)withopen("test.txt","w")asf:......
  • 【Luinx】Linux常用命令Free -g
    一、参考资料​​Linuxfree-g详解_flowerspring的博客Linux中Swap与Memory内存介绍-付杰博客​​Elasticsearch内存占用分析与管理|Tink'sBlog​​​​linuxfree......
  • linux网络配置、dhcp服务器配置 -考前总结
    linux网络配置基础修改主机名hostname命令查看当前主机名hostnameabc将主机名临时更改为abc如果要永久更改就需要修改配置文件/etc/sysconfig/network将HOSTNAME的......
  • 嵌入式-Linux基础:Windows和Linux间的文件传输方式
    首先必须安装VMWare里面的VmWareTool(1)拖拽方式:安装完之后就可以通过拖拽的方式将Windows的文件移到虚拟机里了,同样虚拟机里的也可以拖拽到Windows中。(2)设置共享文件夹......
  • Python - 实现定时任务
    fromapscheduler.schedulers.blockingimportBlockingSchedulerfromdatetimeimportdatetimedeftest_tick():print(f'timeis{datetime.now()}')if__nam......
  • linux 开机启动脚本
    文件放在/etc/init.d/路径下#!/bin/sh-##ubuntu-fanStart/StopUbuntuFANNetworking##chkconfig:3459801#description:Starts/StopsUbuntuFANNetwork......
  • 解决Linux系统下U盘只读文件系统问题
    https://blog.csdn.net/ojbko/article/details/107483568?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromB......
  • python使用os和socket模块简单进行远程命令执行
    一般来说,os模块自带os.system()和os.popen()两个方法用于命令执行,os.system()用来执行系统命令os.popen()可以理解为把命令执行结果变成文件并可供读写,我们主要使用popen(......
  • python os模块 高频函数(未完待续)
    os.environ>>>importos>>>os.environenviron({'CLUTTER_IM_MODULE':'fcitx','COLORTERM':'truecolor','DBUS_SESSION_BUS_ADDRESS':'unix:path=/run/user/1000/......
  • 07python列表
    这篇文章主要介绍列表的一些知识。函数list首先需要说明的是,列表与元组、字符串一样都是一种序列,但不同的是列表是可变的,即可修改其内容。因为不能像修改列表那样修改字......